diff --git a/Source/PullToRefreshView.swift b/Source/PullToRefreshView.swift index 28658f7..c850c94 100755 --- a/Source/PullToRefreshView.swift +++ b/Source/PullToRefreshView.swift @@ -7,6 +7,15 @@ // import UIKit +/* + Fix: Simultaneous access to memory due to KVO + + For more information regarding this global variable follow the followinf links: + 1. https://developer.apple.com/swift/blog/?id=6 + 2. http://michael-brown.net/2017/swift-and-kvo-context-variables/ + */ +private var kvoContext = "PullToRefreshKVOContext" + open class PullToRefreshView: UIView { enum PullToRefreshState { case pulling @@ -19,14 +28,13 @@ open class PullToRefreshView: UIView { // MARK: Variables let contentOffsetKeyPath = "contentOffset" let contentSizeKeyPath = "contentSize" - var kvoContext = "PullToRefreshKVOContext" fileprivate var options: PullToRefreshOption fileprivate var backgroundView: UIView fileprivate var arrow: UIImageView fileprivate var indicator: UIActivityIndicatorView fileprivate var scrollViewInsets: UIEdgeInsets = UIEdgeInsets.zero - fileprivate var refreshCompletion: ((Void) -> Void)? + fileprivate var refreshCompletion: (() -> Void)? fileprivate var pull: Bool = true fileprivate var positionY:CGFloat = 0 { @@ -78,7 +86,7 @@ open class PullToRefreshView: UIView { fatalError("init(coder:) has not been implemented") } - public init(options: PullToRefreshOption, frame: CGRect, refreshCompletion :((Void) -> Void)?, down:Bool=true) { + public init(options: PullToRefreshOption, frame: CGRect, refreshCompletion :(() -> Void)?, down:Bool=true) { self.options = options self.refreshCompletion = refreshCompletion @@ -262,7 +270,7 @@ open class PullToRefreshView: UIView { fileprivate func arrowRotation() { UIView.animate(withDuration: 0.2, delay: 0, options:[], animations: { // -0.0000001 for the rotation direction control - self.arrow.transform = CGAffineTransform(rotationAngle: CGFloat(M_PI-0.0000001)) + self.arrow.transform = CGAffineTransform(rotationAngle: CGFloat(Double.pi-0.0000001)) }, completion:nil) } diff --git a/Source/UIScrollViewExtension.swift b/Source/UIScrollViewExtension.swift index 249fe52..6c1641d 100755 --- a/Source/UIScrollViewExtension.swift +++ b/Source/UIScrollViewExtension.swift @@ -14,14 +14,14 @@ public extension UIScrollView { return pullToRefreshView as? PullToRefreshView } - public func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) { + public func addPullRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :(() -> Void)?) { let refreshViewFrame = CGRect(x: 0, y: -PullToRefreshConst.height, width: self.frame.size.width, height: PullToRefreshConst.height) let refreshView = PullToRefreshView(options: options, frame: refreshViewFrame, refreshCompletion: refreshCompletion) refreshView.tag = PullToRefreshConst.pullTag addSubview(refreshView) } - public func addPushRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :((Void) -> Void)?) { + public func addPushRefresh(options: PullToRefreshOption = PullToRefreshOption(), refreshCompletion :(() -> Void)?) { let refreshViewFrame = CGRect(x: 0, y: contentSize.height, width: self.frame.size.width, height: PullToRefreshConst.height) let refreshView = PullToRefreshView(options: options, frame: refreshViewFrame, refreshCompletion: refreshCompletion,down: false) refreshView.tag = PullToRefreshConst.pushTag