From d9ea29ca21e99f34afdbc4d740953a6610f6d714 Mon Sep 17 00:00:00 2001 From: tsakurai Date: Tue, 24 Jul 2018 15:42:04 +0900 Subject: [PATCH 1/3] swift 4.1.2 support --- Source/PullToRefreshView.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/PullToRefreshView.swift b/Source/PullToRefreshView.swift index 28658f7..a404475 100755 --- a/Source/PullToRefreshView.swift +++ b/Source/PullToRefreshView.swift @@ -26,7 +26,7 @@ open class PullToRefreshView: 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 +78,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 From 7130979b3ef1adea462c87e9ffdb3af6fd6873f1 Mon Sep 17 00:00:00 2001 From: Alaa Al-Zaibak Date: Tue, 21 Aug 2018 21:39:05 +0300 Subject: [PATCH 2/3] Convert code to swift 4.2 --- .../PullToRefreshSwift.xcodeproj/project.pbxproj | 16 ++++++++++------ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++++++++ Example/PullToRefreshSwift/AppDelegate.swift | 2 +- Example/PullToRefreshSwift/ViewController.swift | 2 +- Source/PullToRefreshView.swift | 8 ++++---- Source/UIScrollViewExtension.swift | 4 ++-- 6 files changed, 26 insertions(+), 14 deletions(-) create mode 100644 Example/PullToRefreshSwift.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Example/PullToRefreshSwift.xcodeproj/project.pbxproj b/Example/PullToRefreshSwift.xcodeproj/project.pbxproj index 826f753..7013f98 100644 --- a/Example/PullToRefreshSwift.xcodeproj/project.pbxproj +++ b/Example/PullToRefreshSwift.xcodeproj/project.pbxproj @@ -198,11 +198,11 @@ TargetAttributes = { C53BEC391A357BCA008A4302 = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; }; C53BEC511A357BCA008A4302 = { CreatedOnToolsVersion = 6.1.1; - LastSwiftMigration = 0800; + LastSwiftMigration = 1000; TestTargetID = C53BEC391A357BCA008A4302; }; }; @@ -394,7 +394,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Debug; }; @@ -407,7 +408,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = Default; + SWIFT_VERSION = 4.2; }; name = Release; }; @@ -424,7 +426,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PullToRefreshSwift.app/PullToRefreshSwift"; }; name = Debug; @@ -438,7 +441,8 @@ LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = "dekatotoro.$(PRODUCT_NAME:rfc1034identifier)"; PRODUCT_NAME = "$(TARGET_NAME)"; - SWIFT_VERSION = 3.0; + SWIFT_SWIFT3_OBJC_INFERENCE = On; + SWIFT_VERSION = 4.2; TEST_HOST = "$(BUILT_PRODUCTS_DIR)/PullToRefreshSwift.app/PullToRefreshSwift"; }; name = Release; diff --git a/Example/PullToRefreshSwift.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example/PullToRefreshSwift.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Example/PullToRefreshSwift.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Example/PullToRefreshSwift/AppDelegate.swift b/Example/PullToRefreshSwift/AppDelegate.swift index 6350b56..aa8b08d 100644 --- a/Example/PullToRefreshSwift/AppDelegate.swift +++ b/Example/PullToRefreshSwift/AppDelegate.swift @@ -14,7 +14,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { return true } diff --git a/Example/PullToRefreshSwift/ViewController.swift b/Example/PullToRefreshSwift/ViewController.swift index daa8430..4e0b5da 100644 --- a/Example/PullToRefreshSwift/ViewController.swift +++ b/Example/PullToRefreshSwift/ViewController.swift @@ -50,7 +50,7 @@ class ViewController: UIViewController, UITableViewDataSource, UITableViewDelega func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { - let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.subtitle, reuseIdentifier: "Cell") + let cell: UITableViewCell = UITableViewCell(style: UITableViewCell.CellStyle.subtitle, reuseIdentifier: "Cell") cell.textLabel?.font = UIFont.italicSystemFont(ofSize: 18) cell.textLabel?.textColor = UIColor(red: 44/255, green: 62/255, blue: 88/255, alpha: 1.0) cell.textLabel?.text = texts[(indexPath as NSIndexPath).row] diff --git a/Source/PullToRefreshView.swift b/Source/PullToRefreshView.swift index a404475..f061abe 100755 --- a/Source/PullToRefreshView.swift +++ b/Source/PullToRefreshView.swift @@ -84,7 +84,7 @@ open class PullToRefreshView: UIView { self.backgroundView = UIView(frame: CGRect(x: 0, y: 0, width: frame.size.width, height: frame.size.height)) self.backgroundView.backgroundColor = self.options.backgroundColor - self.backgroundView.autoresizingMask = UIViewAutoresizing.flexibleWidth + self.backgroundView.autoresizingMask = UIView.AutoresizingMask.flexibleWidth self.arrow = UIImageView(frame: CGRect(x: 0, y: 0, width: 30, height: 30)) self.arrow.autoresizingMask = [.flexibleLeftMargin, .flexibleRightMargin] @@ -92,7 +92,7 @@ open class PullToRefreshView: UIView { self.arrow.image = UIImage(named: PullToRefreshConst.imageName, in: Bundle(for: type(of: self)), compatibleWith: nil) - self.indicator = UIActivityIndicatorView(activityIndicatorStyle: UIActivityIndicatorViewStyle.gray) + self.indicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.gray) self.indicator.bounds = self.arrow.bounds self.indicator.autoresizingMask = self.arrow.autoresizingMask self.indicator.hidesWhenStopped = true @@ -160,7 +160,7 @@ open class PullToRefreshView: UIView { // Alpha set if PullToRefreshConst.alpha { - var alpha = fabs(offsetY) / (self.frame.size.height + 40) + var alpha = abs(offsetY) / (self.frame.size.height + 40) if alpha > 0.8 { alpha = 0.8 } @@ -262,7 +262,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 From 24c5eb02aced2446cc0deede76768b3e68439bc5 Mon Sep 17 00:00:00 2001 From: Alaa Al-Zaibak Date: Sun, 14 Apr 2019 00:40:39 +0300 Subject: [PATCH 3/3] Fixed simultaneous access to memory due to KVO --- Source/PullToRefreshView.swift | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/Source/PullToRefreshView.swift b/Source/PullToRefreshView.swift index f061abe..1b775e4 100755 --- a/Source/PullToRefreshView.swift +++ b/Source/PullToRefreshView.swift @@ -7,6 +7,14 @@ // 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,8 +27,7 @@ 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