Skip to content

Commit a7af54b

Browse files
authored
Merge pull request #12 from rikvdbrule/swift3
Update project to Swift 3
2 parents 8fc51d5 + cfdcff4 commit a7af54b

File tree

7 files changed

+162
-130
lines changed

7 files changed

+162
-130
lines changed

Example/Example.xcodeproj/project.pbxproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,12 @@
137137
2EE3B1B61B559DC600E1DF11 /* Project object */ = {
138138
isa = PBXProject;
139139
attributes = {
140-
LastUpgradeCheck = 0700;
140+
LastUpgradeCheck = 0810;
141141
ORGANIZATIONNAME = NSHint;
142142
TargetAttributes = {
143143
2EE3B1BD1B559DC600E1DF11 = {
144144
CreatedOnToolsVersion = 7.0;
145+
LastSwiftMigration = 0810;
145146
};
146147
};
147148
};
@@ -226,8 +227,10 @@
226227
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
227228
CLANG_WARN_EMPTY_BODY = YES;
228229
CLANG_WARN_ENUM_CONVERSION = YES;
230+
CLANG_WARN_INFINITE_RECURSION = YES;
229231
CLANG_WARN_INT_CONVERSION = YES;
230232
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
233+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
231234
CLANG_WARN_UNREACHABLE_CODE = YES;
232235
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
233236
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -271,8 +274,10 @@
271274
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
272275
CLANG_WARN_EMPTY_BODY = YES;
273276
CLANG_WARN_ENUM_CONVERSION = YES;
277+
CLANG_WARN_INFINITE_RECURSION = YES;
274278
CLANG_WARN_INT_CONVERSION = YES;
275279
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
280+
CLANG_WARN_SUSPICIOUS_MOVE = YES;
276281
CLANG_WARN_UNREACHABLE_CODE = YES;
277282
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
278283
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
@@ -291,6 +296,7 @@
291296
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
292297
MTL_ENABLE_DEBUG_INFO = NO;
293298
SDKROOT = iphoneos;
299+
SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule";
294300
TARGETED_DEVICE_FAMILY = "1,2";
295301
VALIDATE_PRODUCT = YES;
296302
};
@@ -304,6 +310,7 @@
304310
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
305311
PRODUCT_BUNDLE_IDENTIFIER = com.nshint.Example;
306312
PRODUCT_NAME = "$(TARGET_NAME)";
313+
SWIFT_VERSION = 3.0;
307314
};
308315
name = Debug;
309316
};
@@ -315,6 +322,7 @@
315322
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
316323
PRODUCT_BUNDLE_IDENTIFIER = com.nshint.Example;
317324
PRODUCT_NAME = "$(TARGET_NAME)";
325+
SWIFT_VERSION = 3.0;
318326
};
319327
name = Release;
320328
};

Example/Example/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
1313

1414
var window: UIWindow?
1515

16-
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
16+
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
1717
return true
1818
}
1919

Example/Example/FirstViewController.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ class FirstViewController: UICollectionViewController {
2121
}
2222
}
2323

24-
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
24+
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
2525
return numbers.count
2626
}
2727

28-
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
28+
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
2929

30-
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! TextCollectionViewCell
30+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! TextCollectionViewCell
3131
cell.textLabel.text = "\(numbers[indexPath.item])"
3232

3333
return cell
3434
}
3535

36-
override func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
36+
override func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
3737

38-
let temp = numbers.removeAtIndex(sourceIndexPath.item)
39-
numbers.insert(temp, atIndex: destinationIndexPath.item)
38+
let temp = numbers.remove(at: sourceIndexPath.item)
39+
numbers.insert(temp, at: destinationIndexPath.item)
4040
}
4141
}
4242

Example/Example/MainViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ class MainViewController: UIViewController {
3232

3333
extension MainViewController: UITableViewDataSource {
3434

35-
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
35+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
3636
return examples.count
3737
}
3838

39-
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
40-
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
39+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
40+
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
4141
cell.textLabel!.text = examples[indexPath.item].rawValue
4242

4343
return cell
@@ -46,7 +46,7 @@ extension MainViewController: UITableViewDataSource {
4646

4747
extension MainViewController: UITableViewDelegate {
4848

49-
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
50-
self.performSegueWithIdentifier(examples[indexPath.item].segueIdentifier(), sender: self)
49+
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
50+
self.performSegue(withIdentifier: examples[indexPath.item].segueIdentifier(), sender: self)
5151
}
5252
}

Example/Example/SecondViewController.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import UIKit
1111
class SecondViewController: UIViewController {
1212

1313
@IBOutlet weak var collectionView: UICollectionView!
14-
private var numbers: [Int] = []
14+
fileprivate var numbers: [Int] = []
1515

16-
private var longPressGesture: UILongPressGestureRecognizer!
16+
fileprivate var longPressGesture: UILongPressGestureRecognizer!
1717

1818
override func viewDidLoad() {
1919
super.viewDidLoad()
@@ -22,22 +22,22 @@ class SecondViewController: UIViewController {
2222
numbers.append(i)
2323
}
2424

25-
longPressGesture = UILongPressGestureRecognizer(target: self, action: "handleLongGesture:")
25+
longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(SecondViewController.handleLongGesture(_:)))
2626
self.collectionView.addGestureRecognizer(longPressGesture)
2727
}
2828

29-
func handleLongGesture(gesture: UILongPressGestureRecognizer) {
29+
func handleLongGesture(_ gesture: UILongPressGestureRecognizer) {
3030

3131
switch(gesture.state) {
3232

33-
case UIGestureRecognizerState.Began:
34-
guard let selectedIndexPath = self.collectionView.indexPathForItemAtPoint(gesture.locationInView(self.collectionView)) else {
33+
case UIGestureRecognizerState.began:
34+
guard let selectedIndexPath = self.collectionView.indexPathForItem(at: gesture.location(in: self.collectionView)) else {
3535
break
3636
}
37-
collectionView.beginInteractiveMovementForItemAtIndexPath(selectedIndexPath)
38-
case UIGestureRecognizerState.Changed:
39-
collectionView.updateInteractiveMovementTargetPosition(gesture.locationInView(gesture.view!))
40-
case UIGestureRecognizerState.Ended:
37+
collectionView.beginInteractiveMovementForItem(at: selectedIndexPath)
38+
case UIGestureRecognizerState.changed:
39+
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!))
40+
case UIGestureRecognizerState.ended:
4141
collectionView.endInteractiveMovement()
4242
default:
4343
collectionView.cancelInteractiveMovement()
@@ -48,22 +48,22 @@ class SecondViewController: UIViewController {
4848

4949
extension SecondViewController: UICollectionViewDataSource {
5050

51-
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
51+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
5252
return numbers.count
5353
}
5454

55-
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
55+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
5656

57-
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! TextCollectionViewCell
57+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! TextCollectionViewCell
5858
cell.textLabel.text = "\(numbers[indexPath.item])"
5959

6060
return cell
6161
}
6262

63-
func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
63+
func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
6464

65-
let temp = numbers.removeAtIndex(sourceIndexPath.item)
66-
numbers.insert(temp, atIndex: destinationIndexPath.item)
65+
let temp = numbers.remove(at: sourceIndexPath.item)
66+
numbers.insert(temp, at: destinationIndexPath.item)
6767
}
6868

6969
}

Example/Example/ThirdViewController.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import UIKit
1111
class ThirdViewController: UIViewController {
1212

1313
@IBOutlet weak var collectionView: UICollectionView!
14-
private var numbers: [Int] = []
14+
fileprivate var numbers: [Int] = []
1515

16-
private var longPressGesture: UILongPressGestureRecognizer!
16+
fileprivate var longPressGesture: UILongPressGestureRecognizer!
1717

1818
override func viewDidLoad() {
1919
super.viewDidLoad()
@@ -23,22 +23,22 @@ class ThirdViewController: UIViewController {
2323
numbers.append(height)
2424
}
2525

26-
longPressGesture = UILongPressGestureRecognizer(target: self, action: "handleLongGesture:")
26+
longPressGesture = UILongPressGestureRecognizer(target: self, action: #selector(ThirdViewController.handleLongGesture(_:)))
2727
self.collectionView.addGestureRecognizer(longPressGesture)
2828
}
2929

30-
func handleLongGesture(gesture: UILongPressGestureRecognizer) {
30+
func handleLongGesture(_ gesture: UILongPressGestureRecognizer) {
3131

3232
switch(gesture.state) {
3333

34-
case UIGestureRecognizerState.Began:
35-
guard let selectedIndexPath = self.collectionView.indexPathForItemAtPoint(gesture.locationInView(self.collectionView)) else {
34+
case UIGestureRecognizerState.began:
35+
guard let selectedIndexPath = self.collectionView.indexPathForItem(at: gesture.location(in: self.collectionView)) else {
3636
break
3737
}
38-
collectionView.beginInteractiveMovementForItemAtIndexPath(selectedIndexPath)
39-
case UIGestureRecognizerState.Changed:
40-
collectionView.updateInteractiveMovementTargetPosition(gesture.locationInView(gesture.view!))
41-
case UIGestureRecognizerState.Ended:
38+
collectionView.beginInteractiveMovementForItem(at: selectedIndexPath)
39+
case UIGestureRecognizerState.changed:
40+
collectionView.updateInteractiveMovementTargetPosition(gesture.location(in: gesture.view!))
41+
case UIGestureRecognizerState.ended:
4242
collectionView.endInteractiveMovement()
4343
default:
4444
collectionView.cancelInteractiveMovement()
@@ -49,42 +49,42 @@ class ThirdViewController: UIViewController {
4949

5050
extension ThirdViewController: CHTCollectionViewDelegateWaterfallLayout {
5151

52-
func collectionView (collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
53-
sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
52+
func collectionView (_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout,
53+
sizeForItemAtIndexPath indexPath: IndexPath) -> CGSize {
5454
return CGSize(width: Int((view.bounds.width - 40)/3), height: numbers[indexPath.item])
5555
}
5656
}
5757

5858
extension ThirdViewController: UICollectionViewDataSource {
5959

60-
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
60+
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
6161
return numbers.count
6262
}
6363

64-
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
64+
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
6565

66-
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! TextCollectionViewCell
66+
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! TextCollectionViewCell
6767
cell.textLabel.text = "\(numbers[indexPath.item])"
6868

6969
return cell
7070
}
7171

72-
func collectionView(collectionView: UICollectionView, moveItemAtIndexPath sourceIndexPath: NSIndexPath, toIndexPath destinationIndexPath: NSIndexPath) {
72+
func collectionView(_ collectionView: UICollectionView, moveItemAt sourceIndexPath: IndexPath, to destinationIndexPath: IndexPath) {
7373

74-
let temp = numbers.removeAtIndex(sourceIndexPath.item)
75-
numbers.insert(temp, atIndex: destinationIndexPath.item)
74+
let temp = numbers.remove(at: sourceIndexPath.item)
75+
numbers.insert(temp, at: destinationIndexPath.item)
7676
}
7777

7878
}
7979

8080
//MARK: one little trick
8181
extension CHTCollectionViewWaterfallLayout {
8282

83-
internal override func invalidationContextForInteractivelyMovingItems(targetIndexPaths: [NSIndexPath], withTargetPosition targetPosition: CGPoint, previousIndexPaths: [NSIndexPath], previousPosition: CGPoint) -> UICollectionViewLayoutInvalidationContext {
83+
internal override func invalidationContext(forInteractivelyMovingItems targetIndexPaths: [IndexPath], withTargetPosition targetPosition: CGPoint, previousIndexPaths: [IndexPath], previousPosition: CGPoint) -> UICollectionViewLayoutInvalidationContext {
8484

85-
let context = super.invalidationContextForInteractivelyMovingItems(targetIndexPaths, withTargetPosition: targetPosition, previousIndexPaths: previousIndexPaths, previousPosition: previousPosition)
85+
let context = super.invalidationContext(forInteractivelyMovingItems: targetIndexPaths, withTargetPosition: targetPosition, previousIndexPaths: previousIndexPaths, previousPosition: previousPosition)
8686

87-
self.delegate?.collectionView!(self.collectionView!, moveItemAtIndexPath: previousIndexPaths[0], toIndexPath: targetIndexPaths[0])
87+
self.delegate?.collectionView!(self.collectionView!, moveItemAt: previousIndexPaths[0], to: targetIndexPaths[0])
8888

8989
return context
9090
}

0 commit comments

Comments
 (0)