Skip to content

Commit

Permalink
Convert to swift3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
yageek committed Dec 1, 2016
1 parent e3d3452 commit 699b62e
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 28 deletions.
1 change: 1 addition & 0 deletions .swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.1
42 changes: 36 additions & 6 deletions StickyHeader.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,19 @@
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 */; };
0BD75F771D6F348200A2E6CD /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 0BD75F751D6F348200A2E6CD /* Main.storyboard */; };
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;
Expand All @@ -30,13 +31,28 @@
};
/* 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 = "<group>"; };
0B3ABB191D6DF12400479F1D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
0B3ABB1F1D6DF14D00479F1D /* StickyHeader.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickyHeader.swift; sourceTree = "<group>"; };
0B3ABB211D6DF22E00479F1D /* .swiftlint.yml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = .swiftlint.yml; sourceTree = "<group>"; };
0B3ABB241D6DF5F700479F1D /* StickyHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StickyHeaderView.swift; sourceTree = "<group>"; };
0BA68E451DF03F5B00B9EBB8 /* .swift-version */ = {isa = PBXFileReference; lastKnownFileType = text; path = ".swift-version"; sourceTree = "<group>"; };
0BBC459D1D703CE300D536AE /* ViewControllerTwo.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewControllerTwo.swift; sourceTree = "<group>"; };
0BD75F531D6F32C300A2E6CD /* UIScrollViewExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UIScrollViewExtension.swift; sourceTree = "<group>"; };
0BD75F6F1D6F348200A2E6CD /* TestApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = TestApp.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand All @@ -60,7 +76,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
0BD75F831D6F351200A2E6CD /* StickyHeader.framework in Frameworks */,
0BA68E491DF043F100B9EBB8 /* StickyHeader.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -70,6 +86,7 @@
0B3ABB0A1D6DF12400479F1D = {
isa = PBXGroup;
children = (
0BA68E451DF03F5B00B9EBB8 /* .swift-version */,
0B3ABB211D6DF22E00479F1D /* .swiftlint.yml */,
0B3ABB161D6DF12400479F1D /* StickyHeader */,
0BD75F701D6F348200A2E6CD /* TestApp */,
Expand Down Expand Up @@ -152,11 +169,12 @@
0BD75F6B1D6F348200A2E6CD /* Sources */,
0BD75F6C1D6F348200A2E6CD /* Frameworks */,
0BD75F6D1D6F348200A2E6CD /* Resources */,
0BA68E4D1DF043F100B9EBB8 /* Embed Frameworks */,
);
buildRules = (
);
dependencies = (
0BD75F851D6F351800A2E6CD /* PBXTargetDependency */,
0BA68E4C1DF043F100B9EBB8 /* PBXTargetDependency */,
);
name = TestApp;
productName = TestApp;
Expand All @@ -175,9 +193,11 @@
TargetAttributes = {
0B3ABB131D6DF12400479F1D = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 5VGYH76875;
};
0BD75F6E1D6F348200A2E6CD = {
CreatedOnToolsVersion = 7.3.1;
DevelopmentTeam = 5VGYH76875;
};
};
};
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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";
Expand All @@ -394,6 +415,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0.1;
};
name = Debug;
};
Expand All @@ -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";
Expand All @@ -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;
};
Expand Down
17 changes: 9 additions & 8 deletions StickyHeader/StickyHeader.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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))

}

Expand All @@ -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<Void>) {
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)
}
}

Expand Down
8 changes: 4 additions & 4 deletions StickyHeader/StickyHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
11 changes: 5 additions & 6 deletions TestApp/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand All @@ -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)
}
}
8 changes: 4 additions & 4 deletions TestApp/ViewControllerTwo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}()
Expand All @@ -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
}

Expand Down

0 comments on commit 699b62e

Please sign in to comment.