From 699b62e5c2de6c3ce273a3f75b62d4be853e0896 Mon Sep 17 00:00:00 2001 From: Yannick Heinrich Date: Thu, 1 Dec 2016 12:47:29 +0100 Subject: [PATCH] Convert to swift3.0 --- .swift-version | 1 + StickyHeader.xcodeproj/project.pbxproj | 42 ++++++++++++++++++++++---- StickyHeader/StickyHeader.swift | 17 ++++++----- StickyHeader/StickyHeaderView.swift | 8 ++--- TestApp/ViewController.swift | 11 +++---- TestApp/ViewControllerTwo.swift | 8 ++--- 6 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 .swift-version diff --git a/.swift-version b/.swift-version new file mode 100644 index 0000000..cb2b00e --- /dev/null +++ b/.swift-version @@ -0,0 +1 @@ +3.0.1 diff --git a/StickyHeader.xcodeproj/project.pbxproj b/StickyHeader.xcodeproj/project.pbxproj index 0b10838..87f3187 100644 --- a/StickyHeader.xcodeproj/project.pbxproj +++ b/StickyHeader.xcodeproj/project.pbxproj @@ -10,6 +10,8 @@ 0B3ABB181D6DF12400479F1D /* StickyHeader.h in Headers */ = {isa = PBXBuildFile; fileRef = 0B3ABB171D6DF12400479F1D /* StickyHeader.h */; settings = {ATTRIBUTES = (Public, ); }; }; 0B3ABB201D6DF14D00479F1D /* StickyHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3ABB1F1D6DF14D00479F1D /* StickyHeader.swift */; }; 0B3ABB251D6DF5F700479F1D /* StickyHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0B3ABB241D6DF5F700479F1D /* StickyHeaderView.swift */; }; + 0BA68E491DF043F100B9EBB8 /* StickyHeader.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */; }; + 0BA68E4A1DF043F100B9EBB8 /* StickyHeader.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 0BBC459E1D703CE300D536AE /* ViewControllerTwo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BBC459D1D703CE300D536AE /* ViewControllerTwo.swift */; }; 0BD75F541D6F32C300A2E6CD /* UIScrollViewExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD75F531D6F32C300A2E6CD /* UIScrollViewExtension.swift */; }; 0BD75F721D6F348200A2E6CD /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD75F711D6F348200A2E6CD /* AppDelegate.swift */; }; @@ -17,11 +19,10 @@ 0BD75F791D6F348200A2E6CD /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 0BD75F781D6F348200A2E6CD /* Assets.xcassets */; }; 0BD75F7C1D6F348200A2E6CD /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0BD75F7A1D6F348200A2E6CD /* LaunchScreen.storyboard */; }; 0BD75F821D6F34CB00A2E6CD /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0BD75F811D6F34CB00A2E6CD /* ViewController.swift */; }; - 0BD75F831D6F351200A2E6CD /* StickyHeader.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ - 0BD75F841D6F351800A2E6CD /* PBXContainerItemProxy */ = { + 0BA68E4B1DF043F100B9EBB8 /* PBXContainerItemProxy */ = { isa = PBXContainerItemProxy; containerPortal = 0B3ABB0B1D6DF12400479F1D /* Project object */; proxyType = 1; @@ -30,6 +31,20 @@ }; /* End PBXContainerItemProxy section */ +/* Begin PBXCopyFilesBuildPhase section */ + 0BA68E4D1DF043F100B9EBB8 /* Embed Frameworks */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = ""; + dstSubfolderSpec = 10; + files = ( + 0BA68E4A1DF043F100B9EBB8 /* StickyHeader.framework in Embed Frameworks */, + ); + name = "Embed Frameworks"; + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXCopyFilesBuildPhase section */ + /* Begin PBXFileReference section */ 0B3ABB141D6DF12400479F1D /* StickyHeader.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = StickyHeader.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 0B3ABB171D6DF12400479F1D /* StickyHeader.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = StickyHeader.h; sourceTree = ""; }; @@ -37,6 +52,7 @@ 0B3ABB1F1D6DF14D00479F1D /* StickyHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickyHeader.swift; sourceTree = ""; }; 0B3ABB211D6DF22E00479F1D /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = ""; }; 0B3ABB241D6DF5F700479F1D /* StickyHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickyHeaderView.swift; sourceTree = ""; }; + 0BA68E451DF03F5B00B9EBB8 /* .swift-version */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".swift-version"; sourceTree = ""; }; 0BBC459D1D703CE300D536AE /* ViewControllerTwo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerTwo.swift; sourceTree = ""; }; 0BD75F531D6F32C300A2E6CD /* UIScrollViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScrollViewExtension.swift; sourceTree = ""; }; 0BD75F6F1D6F348200A2E6CD /* TestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -60,7 +76,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - 0BD75F831D6F351200A2E6CD /* StickyHeader.framework in Frameworks */, + 0BA68E491DF043F100B9EBB8 /* StickyHeader.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -70,6 +86,7 @@ 0B3ABB0A1D6DF12400479F1D = { isa = PBXGroup; children = ( + 0BA68E451DF03F5B00B9EBB8 /* .swift-version */, 0B3ABB211D6DF22E00479F1D /* .swiftlint.yml */, 0B3ABB161D6DF12400479F1D /* StickyHeader */, 0BD75F701D6F348200A2E6CD /* TestApp */, @@ -152,11 +169,12 @@ 0BD75F6B1D6F348200A2E6CD /* Sources */, 0BD75F6C1D6F348200A2E6CD /* Frameworks */, 0BD75F6D1D6F348200A2E6CD /* Resources */, + 0BA68E4D1DF043F100B9EBB8 /* Embed Frameworks */, ); buildRules = ( ); dependencies = ( - 0BD75F851D6F351800A2E6CD /* PBXTargetDependency */, + 0BA68E4C1DF043F100B9EBB8 /* PBXTargetDependency */, ); name = TestApp; productName = TestApp; @@ -175,9 +193,11 @@ TargetAttributes = { 0B3ABB131D6DF12400479F1D = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 5VGYH76875; }; 0BD75F6E1D6F348200A2E6CD = { CreatedOnToolsVersion = 7.3.1; + DevelopmentTeam = 5VGYH76875; }; }; }; @@ -261,10 +281,10 @@ /* End PBXSourcesBuildPhase section */ /* Begin PBXTargetDependency section */ - 0BD75F851D6F351800A2E6CD /* PBXTargetDependency */ = { + 0BA68E4C1DF043F100B9EBB8 /* PBXTargetDependency */ = { isa = PBXTargetDependency; target = 0B3ABB131D6DF12400479F1D /* StickyHeader */; - targetProxy = 0BD75F841D6F351800A2E6CD /* PBXContainerItemProxy */; + targetProxy = 0BA68E4B1DF043F100B9EBB8 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -384,6 +404,7 @@ buildSettings = { CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = 5VGYH76875; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -394,6 +415,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + SWIFT_VERSION = 3.0.1; }; name = Debug; }; @@ -402,6 +424,7 @@ buildSettings = { CLANG_ENABLE_MODULES = YES; DEFINES_MODULE = YES; + DEVELOPMENT_TEAM = 5VGYH76875; DYLIB_COMPATIBILITY_VERSION = 1; DYLIB_CURRENT_VERSION = 1; DYLIB_INSTALL_NAME_BASE = "@rpath"; @@ -411,28 +434,35 @@ PRODUCT_BUNDLE_IDENTIFIER = net.yageek.StickyHeader; PRODUCT_NAME = "$(TARGET_NAME)"; SKIP_INSTALL = YES; + SWIFT_VERSION = 3.0.1; }; name = Release; }; 0BD75F7F1D6F348200A2E6CD /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 5VGYH76875; INFOPLIST_FILE = TestApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.yageek.TestApp; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0.1; }; name = Debug; }; 0BD75F801D6F348200A2E6CD /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + DEVELOPMENT_TEAM = 5VGYH76875; INFOPLIST_FILE = TestApp/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; PRODUCT_BUNDLE_IDENTIFIER = net.yageek.TestApp; PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_VERSION = 3.0.1; }; name = Release; }; diff --git a/StickyHeader/StickyHeader.swift b/StickyHeader/StickyHeader.swift index d1852e4..942850e 100644 --- a/StickyHeader/StickyHeader.swift +++ b/StickyHeader/StickyHeader.swift @@ -38,7 +38,7 @@ public class StickyHeader: NSObject { _scrollView = newValue if let scrollView = scrollView { - self.adjustScrollViewTopInset(scrollView.contentInset.top + self.height) + self.adjustScrollViewTopInset(top: scrollView.contentInset.top + self.height) scrollView.addSubview(self.contentView) } @@ -74,7 +74,7 @@ public class StickyHeader: NSObject { guard newValue != _height else { return } if let scrollView = self.scrollView { - self.adjustScrollViewTopInset(scrollView.contentInset.top - height + newValue) + self.adjustScrollViewTopInset(top: scrollView.contentInset.top - height + newValue) } _height = newValue @@ -121,11 +121,11 @@ public class StickyHeader: NSObject { view.translatesAutoresizingMaskIntoConstraints = false - self.contentView.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[v]|", options: [], metrics: nil, views: ["v": view])) + self.contentView.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|[v]|", options: [], metrics: nil, views: ["v": view])) - self.contentView.addConstraint(NSLayoutConstraint(item: view, attribute: .CenterY, relatedBy: .Equal, toItem: contentView, attribute: .CenterY, multiplier: 1, constant: 0)) + self.contentView.addConstraint(NSLayoutConstraint(item: view, attribute: .centerY, relatedBy: .equal, toItem: contentView, attribute: .centerY, multiplier: 1, constant: 0)) - self.contentView.addConstraint(NSLayoutConstraint(item: view, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1, constant: self.height)) + self.contentView.addConstraint(NSLayoutConstraint(item: view, attribute: .height, relatedBy: .equal, toItem: nil, attribute: .notAnAttribute, multiplier: 1, constant: self.height)) } @@ -147,11 +147,12 @@ public class StickyHeader: NSObject { self.contentView.frame = frame } - public override func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) { - if let path = keyPath where context == &StickyHeaderView.KVOContext && path == "contentOffset" { + + public override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) { + if let path = keyPath, context == &StickyHeaderView.KVOContext && path == "contentOffset" { self.layoutContentView() } else { - super.observeValueForKeyPath(keyPath, ofObject: object, change: change, context: context) + super.observeValue(forKeyPath: keyPath, of: object, change: change, context: context) } } diff --git a/StickyHeader/StickyHeaderView.swift b/StickyHeader/StickyHeaderView.swift index 5c04256..31a929c 100644 --- a/StickyHeader/StickyHeaderView.swift +++ b/StickyHeader/StickyHeaderView.swift @@ -13,15 +13,15 @@ internal class StickyHeaderView: UIView { internal static var KVOContext = 0 - override func willMoveToSuperview(newSuperview: UIView?) { - if let view = self.superview where view.isKindOfClass(UIScrollView.self), let parent = self.parent { + override func willMove(toSuperview view: UIView?) { + if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = self.parent { view.removeObserver(parent, forKeyPath: "contentOffset", context: &StickyHeaderView.KVOContext) } } override func didMoveToSuperview() { - if let view = self.superview where view.isKindOfClass(UIScrollView.self), let parent = parent { - view.addObserver(parent, forKeyPath: "contentOffset", options: .New, context: &StickyHeaderView.KVOContext) + if let view = self.superview, view.isKind(of:UIScrollView.self), let parent = parent { + view.addObserver(parent, forKeyPath: "contentOffset", options: .new, context: &StickyHeaderView.KVOContext) } } } diff --git a/TestApp/ViewController.swift b/TestApp/ViewController.swift index 2e4124f..1797e46 100644 --- a/TestApp/ViewController.swift +++ b/TestApp/ViewController.swift @@ -15,7 +15,7 @@ class ViewController: UICollectionViewController { let headerView: UIView = { let view = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100)) - view.backgroundColor = UIColor.blueColor() + view.backgroundColor = UIColor.blue view.translatesAutoresizingMaskIntoConstraints = false return view }() @@ -34,16 +34,15 @@ class ViewController: UICollectionViewController { // Dispose of any resources that can be recreated. } - override func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { + override func numberOfSections(in collectionView: UICollectionView) -> Int { return 1 } - override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { + override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { return 1000 } - override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { - - return collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) + override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { + return collectionView.dequeueReusableCell(withReuseIdentifier:"Cell", for: indexPath) } } diff --git a/TestApp/ViewControllerTwo.swift b/TestApp/ViewControllerTwo.swift index 3a31d09..758b8b9 100644 --- a/TestApp/ViewControllerTwo.swift +++ b/TestApp/ViewControllerTwo.swift @@ -12,7 +12,7 @@ class ViewControllerTwo: UITableViewController { let headerView: UIView = { let view = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: 100)) - view.backgroundColor = UIColor.blueColor() + view.backgroundColor = UIColor.blue view.translatesAutoresizingMaskIntoConstraints = false return view }() @@ -26,13 +26,13 @@ class ViewControllerTwo: UITableViewController { } // MARK: - Table view data source - override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return 1000 } - override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { - let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier:"Cell", for: indexPath) return cell }