Skip to content

Commit e4c5432

Browse files
authored
Merge pull request #2 from naeemshaikh90/master
Swift 3 Support
2 parents bc9f9ac + a3ab5b1 commit e4c5432

13 files changed

Lines changed: 149 additions & 128 deletions

File tree

Example/YBSlantedCollectionViewLayoutSample.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,12 @@
158158
isa = PBXProject;
159159
attributes = {
160160
LastSwiftUpdateCheck = 0720;
161-
LastUpgradeCheck = 0720;
161+
LastUpgradeCheck = 0820;
162162
ORGANIZATIONNAME = "Yassir Barchi";
163163
TargetAttributes = {
164164
FB17358A1C83A0B400EEDB5F = {
165165
CreatedOnToolsVersion = 7.2.1;
166+
LastSwiftMigration = 0820;
166167
};
167168
};
168169
};
@@ -267,8 +268,10 @@
267268
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
268269
CLANG_WARN_EMPTY_BODY = YES;
269270
CLANG_WARN_ENUM_CONVERSION = YES;
271+
CLANG_WARN_INFINITE_RECURSION = YES;
270272
CLANG_WARN_INT_CONVERSION = YES;
271273
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
274+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
272275
CLANG_WARN_UNREACHABLE_CODE = YES;
273276
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
274277
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -311,8 +314,10 @@
311314
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
312315
CLANG_WARN_EMPTY_BODY = YES;
313316
CLANG_WARN_ENUM_CONVERSION = YES;
317+
CLANG_WARN_INFINITE_RECURSION = YES;
314318
CLANG_WARN_INT_CONVERSION = YES;
315319
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
320+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
316321
CLANG_WARN_UNREACHABLE_CODE = YES;
317322
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
318323
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -331,6 +336,7 @@
331336
IPHONEOS_DEPLOYMENT_TARGET = 9.2;
332337
MTL_ENABLE_DEBUG_INFO = NO;
333338
SDKROOT = iphoneos;
339+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
334340
VALIDATE_PRODUCT = YES;
335341
};
336342
name = Release;
@@ -345,6 +351,7 @@
345351
PRODUCT_BUNDLE_IDENTIFIER = YB.YBSlantedCollectionViewLayoutSample;
346352
PRODUCT_NAME = "$(TARGET_NAME)";
347353
SWIFT_OBJC_BRIDGING_HEADER = "";
354+
SWIFT_VERSION = 3.0;
348355
};
349356
name = Debug;
350357
};
@@ -358,6 +365,7 @@
358365
PRODUCT_BUNDLE_IDENTIFIER = YB.YBSlantedCollectionViewLayoutSample;
359366
PRODUCT_NAME = "$(TARGET_NAME)";
360367
SWIFT_OBJC_BRIDGING_HEADER = "";
368+
SWIFT_VERSION = 3.0;
361369
};
362370
name = Release;
363371
};

Example/YBSlantedCollectionViewLayoutSample/AppDelegate.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,30 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1414
var window: UIWindow?
1515

1616

17-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
17+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1818
// Override point for customization after application launch.
1919
return true
2020
}
2121

22-
func applicationWillResignActive(application: UIApplication) {
22+
func applicationWillResignActive(_ application: UIApplication) {
2323
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
2424
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
2525
}
2626

27-
func applicationDidEnterBackground(application: UIApplication) {
27+
func applicationDidEnterBackground(_ application: UIApplication) {
2828
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
2929
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
3030
}
3131

32-
func applicationWillEnterForeground(application: UIApplication) {
32+
func applicationWillEnterForeground(_ application: UIApplication) {
3333
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
3434
}
3535

36-
func applicationDidBecomeActive(application: UIApplication) {
36+
func applicationDidBecomeActive(_ application: UIApplication) {
3737
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
3838
}
3939

40-
func applicationWillTerminate(application: UIApplication) {
40+
func applicationWillTerminate(_ application: UIApplication) {
4141
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
4242
}
4343

Example/YBSlantedCollectionViewLayoutSample/CustomCollectionCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class CustomCollectionCell: YBSlantedCollectionViewCell {
3434
}
3535

3636

37-
func offset(offset: CGPoint) {
38-
imageView.frame = CGRectOffset(self.imageView.bounds, offset.x, offset.y)
37+
func offset(_ offset: CGPoint) {
38+
imageView.frame = self.imageView.bounds.offsetBy(dx: offset.x, dy: offset.y)
3939
}
40-
}
40+
}

Example/YBSlantedCollectionViewLayoutSample/SettingsController.swift

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,59 +26,59 @@ class SettingsController: UITableViewController {
2626
override func viewDidLoad() {
2727
super.viewDidLoad()
2828

29-
self.reverseSlantingDirectionSwitch.on = self.collectionViewLayout.reverseSlantingAngle
30-
self.firstCellSlantingSwitch.on = self.collectionViewLayout.firstCellSlantingEnabled
31-
self.lastCellSlantingSwitch.on = self.collectionViewLayout.lastCellSlantingEnabled
32-
self.scrollDirectionSwitch.on = self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirection.Horizontal
29+
self.reverseSlantingDirectionSwitch.isOn = self.collectionViewLayout.reverseSlantingAngle
30+
self.firstCellSlantingSwitch.isOn = self.collectionViewLayout.firstCellSlantingEnabled
31+
self.lastCellSlantingSwitch.isOn = self.collectionViewLayout.lastCellSlantingEnabled
32+
self.scrollDirectionSwitch.isOn = self.collectionViewLayout.scrollDirection == UICollectionViewScrollDirection.horizontal
3333
self.slantingDeltaSlider.value = Float(self.collectionViewLayout.slantingDelta)
3434
self.lineSpacingSlider.value = Float(self.collectionViewLayout.lineSpacing)
3535

3636

37-
UIApplication.sharedApplication().setStatusBarHidden(false, withAnimation: UIStatusBarAnimation.Slide)
37+
UIApplication.shared.setStatusBarHidden(false, with: UIStatusBarAnimation.slide)
3838

3939
}
4040

41-
override func prefersStatusBarHidden() -> Bool {
41+
override var prefersStatusBarHidden : Bool {
4242
return false
4343
}
4444

45-
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
46-
return UIStatusBarAnimation.Slide
45+
override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
46+
return UIStatusBarAnimation.slide
4747
}
4848

49-
@IBAction func slantingDirectionChanged(sender: UISwitch) {
50-
self.collectionViewLayout.reverseSlantingAngle = sender.on
49+
@IBAction func slantingDirectionChanged(_ sender: UISwitch) {
50+
self.collectionViewLayout.reverseSlantingAngle = sender.isOn
5151
}
5252

53-
@IBAction func firstCellSlantingSwitchChanged(sender: UISwitch) {
54-
self.collectionViewLayout.firstCellSlantingEnabled = sender.on
53+
@IBAction func firstCellSlantingSwitchChanged(_ sender: UISwitch) {
54+
self.collectionViewLayout.firstCellSlantingEnabled = sender.isOn
5555
}
5656

57-
@IBAction func lastCellSlantingSwitchChanged(sender: UISwitch) {
58-
self.collectionViewLayout.lastCellSlantingEnabled = sender.on
57+
@IBAction func lastCellSlantingSwitchChanged(_ sender: UISwitch) {
58+
self.collectionViewLayout.lastCellSlantingEnabled = sender.isOn
5959
}
6060

61-
@IBAction func scrollDirectionChanged(sender: UISwitch) {
62-
if sender.on {
63-
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.Horizontal
61+
@IBAction func scrollDirectionChanged(_ sender: UISwitch) {
62+
if sender.isOn {
63+
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.horizontal
6464
}
6565
else {
66-
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.Vertical
66+
self.collectionViewLayout.scrollDirection = UICollectionViewScrollDirection.vertical
6767
}
6868
self.collectionViewLayout.collectionView?.reloadData()
6969
}
7070

7171

72-
@IBAction func slantingDeltaChanged(sender: UISlider) {
72+
@IBAction func slantingDeltaChanged(_ sender: UISlider) {
7373
self.collectionViewLayout.slantingDelta = UInt(sender.value)
7474
}
7575

76-
@IBAction func lineSpacingChanged(sender: UISlider) {
76+
@IBAction func lineSpacingChanged(_ sender: UISlider) {
7777
self.collectionViewLayout.lineSpacing = CGFloat(sender.value)
7878
}
79-
@IBAction func done(sender: AnyObject) {
80-
self.presentingViewController?.dismissViewControllerAnimated(true, completion: { () -> Void in
81-
self.collectionViewLayout.collectionView?.scrollRectToVisible(CGRectMake(0, 0, 0, 0), animated: true);
79+
@IBAction func done(_ sender: AnyObject) {
80+
self.presentingViewController?.dismiss(animated: true, completion: { () -> Void in
81+
self.collectionViewLayout.collectionView?.scrollRectToVisible(CGRect(x: 0, y: 0, width: 0, height: 0), animated: true);
8282
})
8383
}
8484
}

Example/YBSlantedCollectionViewLayoutSample/ViewController.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -29,31 +29,31 @@ class ViewController: UIViewController {
2929
}
3030
}
3131

32-
self.navigationController?.navigationBarHidden = true
32+
self.navigationController?.isNavigationBarHidden = true
3333
}
3434

35-
override func viewWillAppear(animated: Bool) {
35+
override func viewWillAppear(_ animated: Bool) {
3636
super.viewWillAppear(animated)
3737
self.collectionView.reloadData()
38-
UIApplication.sharedApplication().setStatusBarHidden(true, withAnimation: UIStatusBarAnimation.Slide)
38+
UIApplication.shared.setStatusBarHidden(true, with: UIStatusBarAnimation.slide)
3939
}
4040

41-
override func prefersStatusBarHidden() -> Bool {
41+
override var prefersStatusBarHidden : Bool {
4242
return true
4343
}
4444

45-
override func preferredStatusBarUpdateAnimation() -> UIStatusBarAnimation {
46-
return UIStatusBarAnimation.Slide
45+
override var preferredStatusBarUpdateAnimation : UIStatusBarAnimation {
46+
return UIStatusBarAnimation.slide
4747
}
4848

4949
override func didReceiveMemoryWarning() {
5050
super.didReceiveMemoryWarning()
5151
// Dispose of any resources that can be recreated.
5252
}
5353

54-
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
54+
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
5555
if segue.identifier == "ShowSettings" {
56-
let navigation = segue.destinationViewController as! UINavigationController
56+
let navigation = segue.destination as! UINavigationController
5757

5858
let settingsController = navigation.viewControllers[0] as! SettingsController
5959

@@ -66,14 +66,14 @@ class ViewController: UIViewController {
6666

6767
extension ViewController: UICollectionViewDataSource {
6868

69-
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
69+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
7070
return images.count
7171
}
7272

73-
func collectionView(collectionView: UICollectionView,
74-
cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
73+
func collectionView(_ collectionView: UICollectionView,
74+
cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
7575

76-
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomCollectionCell
76+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! CustomCollectionCell
7777

7878
cell.image = images[indexPath.row]
7979

@@ -83,19 +83,19 @@ extension ViewController: UICollectionViewDataSource {
8383

8484
extension ViewController: UICollectionViewDelegate {
8585

86-
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
86+
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
8787
NSLog("Did select item at indexPath: [\(indexPath.section)][\(indexPath.row)]")
8888
}
8989
}
9090

9191
extension ViewController: UIScrollViewDelegate {
92-
func scrollViewDidScroll(scrollView: UIScrollView) {
92+
func scrollViewDidScroll(_ scrollView: UIScrollView) {
9393
guard let collectionView = self.collectionView else {return}
94-
guard let visibleCells = collectionView.visibleCells() as? [CustomCollectionCell] else {return}
94+
guard let visibleCells = collectionView.visibleCells as? [CustomCollectionCell] else {return}
9595
for parallaxCell in visibleCells {
9696
let yOffset = ((collectionView.contentOffset.y - parallaxCell.frame.origin.y) / parallaxCell.imageHeight) * yOffsetSpeed
9797
let xOffset = ((collectionView.contentOffset.x - parallaxCell.frame.origin.x) / parallaxCell.imageWidth) * xOffsetSpeed
98-
parallaxCell.offset(CGPointMake(xOffset, yOffset))
98+
parallaxCell.offset(CGPoint(x: xOffset,y :yOffset))
9999
}
100100
}
101101
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ github 'yacir/YBSlantedCollectionViewLayout'
6565
- [x] Improve the attribution of the clic
6666
- [x] Carthage support
6767
- [x] Tests
68-
- [ ] Swift 3 support
68+
- [x] Swift 3 support
6969
- [ ] Swift Package Manager support
7070

7171
## Author

Source/YBSlantedCollectionViewCell.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,28 @@ import UIKit
2828
YBSlantedCollectionViewCell is a subclass of UICollectionViewCell.
2929
Use it or subclass it to apply the slanting mask on your cells.
3030
*/
31-
public class YBSlantedCollectionViewCell: UICollectionViewCell {
31+
open class YBSlantedCollectionViewCell: UICollectionViewCell {
3232

3333
/// :nodoc:
34-
private var slantedLayerMask: CAShapeLayer?
34+
fileprivate var slantedLayerMask: CAShapeLayer?
3535

3636
/// :nodoc:
37-
override public func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
37+
override open func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
3838

3939
if (self.slantedLayerMask != nil) {
4040
let bezierPath = UIBezierPath()
41-
bezierPath.CGPath = self.slantedLayerMask!.path!
42-
let result = bezierPath.containsPoint(point)
41+
bezierPath.cgPath = self.slantedLayerMask!.path!
42+
let result = bezierPath.contains(point)
4343
return result
4444
}
4545

46-
return (super.pointInside(point, withEvent: event))
46+
return (super.point(inside: point, with: event))
4747
}
4848

4949
/// :nodoc:
50-
override public func applyLayoutAttributes(layoutAttributes: UICollectionViewLayoutAttributes) {
50+
override open func apply(_ layoutAttributes: UICollectionViewLayoutAttributes) {
5151
let attributes = layoutAttributes as! YBSlantedCollectionViewLayoutAttributes
52-
super.applyLayoutAttributes(attributes)
52+
super.apply(attributes)
5353
self.slantedLayerMask = attributes.slantedLayerMask
5454
self.layer.mask = attributes.slantedLayerMask
5555
}

0 commit comments

Comments
 (0)