Skip to content

Commit

Permalink
Merge pull request #2 from patrickreynolds/master
Browse files Browse the repository at this point in the history
Remove implicitly unwrapped optionals in Observer and OnceToken getters
  • Loading branch information
ronghaopger committed Mar 11, 2016
2 parents 9204ec0 + fd11dcd commit 2562808
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
20 changes: 11 additions & 9 deletions Demo/Demo/EasyPull/UIScrollView+EasyPull.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ extension UIScrollView {
// MARK: - constant and veriable and property
private var Observer: EasyObserver {
get {
var obj = objc_getAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver) as? EasyObserver
if obj == nil {
obj = EasyObserver(scrollView: self)
if let obj = objc_getAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver) as? EasyObserver {
return obj
} else {
let obj = EasyObserver(scrollView: self)
objc_setAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver, obj, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return obj
}
return obj!
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
Expand All @@ -31,18 +32,19 @@ extension UIScrollView {

private var OnceToken: dispatch_once_t {
get {
var token = objc_getAssociatedObject(self, &AssociatedKeys.OnceToken) as? dispatch_once_t
if token == nil {
token = 0
if let token = objc_getAssociatedObject(self, &AssociatedKeys.OnceToken) as? dispatch_once_t {
return token
} else {
let token = 0
objc_setAssociatedObject(self, &AssociatedKeys.OnceToken, token, .OBJC_ASSOCIATION_ASSIGN)
return token
}
return token!
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.OnceToken, newValue, .OBJC_ASSOCIATION_ASSIGN)
}
}

// MARK: - public method
/**
add drop pull to refresh
Expand Down
20 changes: 11 additions & 9 deletions EasyPull/EasyPull/UIScrollView+EasyPull.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ extension UIScrollView {
// MARK: - constant and veriable and property
private var Observer: EasyObserver {
get {
var obj = objc_getAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver) as? EasyObserver
if obj == nil {
obj = EasyObserver(scrollView: self)
if let obj = objc_getAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver) as? EasyObserver {
return obj
} else {
let obj = EasyObserver(scrollView: self)
objc_setAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver, obj, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
return obj
}
return obj!
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.ContentOffsetObserver, newValue, .OBJC_ASSOCIATION_RETAIN_NONATOMIC)
Expand All @@ -31,18 +32,19 @@ extension UIScrollView {

private var OnceToken: dispatch_once_t {
get {
var token = objc_getAssociatedObject(self, &AssociatedKeys.OnceToken) as? dispatch_once_t
if token == nil {
token = 0
if let token = objc_getAssociatedObject(self, &AssociatedKeys.OnceToken) as? dispatch_once_t {
return token
} else {
let token = 0
objc_setAssociatedObject(self, &AssociatedKeys.OnceToken, token, .OBJC_ASSOCIATION_ASSIGN)
return token
}
return token!
}
set {
objc_setAssociatedObject(self, &AssociatedKeys.OnceToken, newValue, .OBJC_ASSOCIATION_ASSIGN)
}
}

// MARK: - public method
/**
add drop pull to refresh
Expand Down

0 comments on commit 2562808

Please sign in to comment.