Skip to content

Commit ae2ed42

Browse files
committed
update to swift 3.0
1 parent c64791c commit ae2ed42

11 files changed

+105
-105
lines changed

Example.xcodeproj/project.pbxproj

+8-6
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@
507507
PRODUCT_NAME = StatefulViewController;
508508
SKIP_INSTALL = YES;
509509
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
510-
SWIFT_VERSION = 2.3;
510+
SWIFT_VERSION = 3.0;
511511
TARGETED_DEVICE_FAMILY = "1,2";
512512
VERSIONING_SYSTEM = "apple-generic";
513513
VERSION_INFO_PREFIX = "";
@@ -532,7 +532,7 @@
532532
PRODUCT_BUNDLE_IDENTIFIER = com.aschuch.StatefulViewController;
533533
PRODUCT_NAME = StatefulViewController;
534534
SKIP_INSTALL = YES;
535-
SWIFT_VERSION = 2.3;
535+
SWIFT_VERSION = 3.0;
536536
TARGETED_DEVICE_FAMILY = "1,2";
537537
VERSIONING_SYSTEM = "apple-generic";
538538
VERSION_INFO_PREFIX = "";
@@ -552,7 +552,7 @@
552552
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
553553
PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)";
554554
PRODUCT_NAME = "$(TARGET_NAME)";
555-
SWIFT_VERSION = 2.3;
555+
SWIFT_VERSION = 3.0;
556556
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
557557
};
558558
name = Debug;
@@ -567,7 +567,7 @@
567567
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks";
568568
PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)";
569569
PRODUCT_NAME = "$(TARGET_NAME)";
570-
SWIFT_VERSION = 2.3;
570+
SWIFT_VERSION = 3.0;
571571
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/Example.app/Example";
572572
};
573573
name = Release;
@@ -665,7 +665,7 @@
665665
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
666666
PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)";
667667
PRODUCT_NAME = "$(TARGET_NAME)";
668-
SWIFT_VERSION = 2.3;
668+
SWIFT_VERSION = 3.0;
669669
};
670670
name = Debug;
671671
};
@@ -677,7 +677,7 @@
677677
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
678678
PRODUCT_BUNDLE_IDENTIFIER = "com.aschuch.$(PRODUCT_NAME:rfc1034identifier)";
679679
PRODUCT_NAME = "$(TARGET_NAME)";
680-
SWIFT_VERSION = 2.3;
680+
SWIFT_VERSION = 3.0;
681681
};
682682
name = Release;
683683
};
@@ -699,6 +699,7 @@
699699
PRODUCT_NAME = StatefulViewController;
700700
SDKROOT = appletvos;
701701
SKIP_INSTALL = YES;
702+
SWIFT_VERSION = 3.0;
702703
TARGETED_DEVICE_FAMILY = 3;
703704
TVOS_DEPLOYMENT_TARGET = 9.0;
704705
VERSIONING_SYSTEM = "apple-generic";
@@ -725,6 +726,7 @@
725726
PRODUCT_NAME = StatefulViewController;
726727
SDKROOT = appletvos;
727728
SKIP_INSTALL = YES;
729+
SWIFT_VERSION = 3.0;
728730
TARGETED_DEVICE_FAMILY = 3;
729731
TVOS_DEPLOYMENT_TARGET = 9.0;
730732
VERSIONING_SYSTEM = "apple-generic";

Example/AppDelegate.swift

+6-8
Original file line numberDiff line numberDiff line change
@@ -13,33 +13,31 @@ 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]? = nil) -> Bool {
1717
// Override point for customization after application launch.
1818
return true
1919
}
2020

21-
func applicationWillResignActive(application: UIApplication) {
21+
func applicationWillResignActive(_ application: UIApplication) {
2222
// 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.
2323
// 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.
2424
}
2525

26-
func applicationDidEnterBackground(application: UIApplication) {
26+
func applicationDidEnterBackground(_ application: UIApplication) {
2727
// 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.
2828
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
2929
}
3030

31-
func applicationWillEnterForeground(application: UIApplication) {
31+
func applicationWillEnterForeground(_ application: UIApplication) {
3232
// 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.
3333
}
3434

35-
func applicationDidBecomeActive(application: UIApplication) {
35+
func applicationDidBecomeActive(_ application: UIApplication) {
3636
// 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.
3737
}
3838

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

43-
4443
}
45-

Example/PlaceholderViews/BasicPlaceholderView.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ class BasicPlaceholderView: UIView {
2525
}
2626

2727
func setupView() {
28-
backgroundColor = UIColor.whiteColor()
28+
backgroundColor = UIColor.white
2929

3030
centerView.translatesAutoresizingMaskIntoConstraints = false
3131
self.addSubview(centerView)
3232

3333
let views = ["centerView": centerView, "superview": self]
34-
let vConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:[superview]-(<=1)-[centerView]",
35-
options: .AlignAllCenterX,
34+
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:[superview]-(<=1)-[centerView]",
35+
options: .alignAllCenterX,
3636
metrics: nil,
3737
views: views)
38-
let hConstraints = NSLayoutConstraint.constraintsWithVisualFormat("H:[superview]-(<=1)-[centerView]",
39-
options: .AlignAllCenterY,
38+
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "H:[superview]-(<=1)-[centerView]",
39+
options: .alignAllCenterY,
4040
metrics: nil,
4141
views: views)
4242
self.addConstraints(vConstraints)

Example/PlaceholderViews/EmptyView.swift

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ class EmptyView: BasicPlaceholderView {
1515
override func setupView() {
1616
super.setupView()
1717

18-
backgroundColor = UIColor.whiteColor()
18+
backgroundColor = UIColor.white
1919

2020
label.text = "No Content."
2121
label.translatesAutoresizingMaskIntoConstraints = false
2222
centerView.addSubview(label)
2323

2424
let views = ["label": label]
25-
let hConstraints = NSLayoutConstraint.constraintsWithVisualFormat("|-[label]-|", options: .AlignAllCenterY, metrics: nil, views: views)
26-
let vConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-[label]-|", options: .AlignAllCenterX, metrics: nil, views: views)
25+
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "|-[label]-|", options: .alignAllCenterY, metrics: nil, views: views)
26+
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[label]-|", options: .alignAllCenterX, metrics: nil, views: views)
2727

2828
centerView.addConstraints(hConstraints)
2929
centerView.addConstraints(vConstraints)

Example/PlaceholderViews/ErrorView.swift

+7-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ErrorView: BasicPlaceholderView {
1717
override func setupView() {
1818
super.setupView()
1919

20-
backgroundColor = UIColor.whiteColor()
20+
backgroundColor = UIColor.white
2121

2222
self.addGestureRecognizer(tapGestureRecognizer)
2323

@@ -26,17 +26,17 @@ class ErrorView: BasicPlaceholderView {
2626
centerView.addSubview(textLabel)
2727

2828
detailTextLabel.text = "Tap to reload"
29-
let fontDescriptor = UIFontDescriptor.preferredFontDescriptorWithTextStyle(UIFontTextStyleFootnote)
29+
let fontDescriptor = UIFontDescriptor.preferredFontDescriptor(withTextStyle: UIFontTextStyle.footnote)
3030
detailTextLabel.font = UIFont(descriptor: fontDescriptor, size: 0)
31-
detailTextLabel.textAlignment = .Center
32-
detailTextLabel.textColor = UIColor.grayColor()
31+
detailTextLabel.textAlignment = .center
32+
detailTextLabel.textColor = UIColor.gray
3333
detailTextLabel.translatesAutoresizingMaskIntoConstraints = false
3434
centerView.addSubview(detailTextLabel)
3535

3636
let views = ["label": textLabel, "detailLabel": detailTextLabel]
37-
let hConstraints = NSLayoutConstraint.constraintsWithVisualFormat("|-[label]-|", options: .AlignAllCenterY, metrics: nil, views: views)
38-
let hConstraintsDetail = NSLayoutConstraint.constraintsWithVisualFormat("|-[detailLabel]-|", options: .AlignAllCenterY, metrics: nil, views: views)
39-
let vConstraints = NSLayoutConstraint.constraintsWithVisualFormat("V:|-[label]-[detailLabel]-|", options: .AlignAllCenterX, metrics: nil, views: views)
37+
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "|-[label]-|", options: .alignAllCenterY, metrics: nil, views: views)
38+
let hConstraintsDetail = NSLayoutConstraint.constraints(withVisualFormat: "|-[detailLabel]-|", options: .alignAllCenterY, metrics: nil, views: views)
39+
let vConstraints = NSLayoutConstraint.constraints(withVisualFormat: "V:|-[label]-[detailLabel]-|", options: .alignAllCenterX, metrics: nil, views: views)
4040

4141
centerView.addConstraints(hConstraints)
4242
centerView.addConstraints(hConstraintsDetail)

Example/PlaceholderViews/LoadingView.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ class LoadingView: BasicPlaceholderView, StatefulPlaceholderView {
1616
override func setupView() {
1717
super.setupView()
1818

19-
backgroundColor = UIColor.redColor()
19+
backgroundColor = UIColor.red
2020

2121
label.text = "Loading..."
2222
label.translatesAutoresizingMaskIntoConstraints = false
2323
centerView.addSubview(label)
2424

25-
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .Gray)
25+
let activityIndicator = UIActivityIndicatorView(activityIndicatorStyle: .gray)
2626
activityIndicator.startAnimating()
2727
activityIndicator.translatesAutoresizingMaskIntoConstraints = false
2828
centerView.addSubview(activityIndicator)
2929

3030
let views = ["label": label, "activity": activityIndicator]
31-
let hConstraints = NSLayoutConstraint.constraintsWithVisualFormat("|-[activity]-[label]-|", options: [], metrics: nil, views: views)
32-
let vConstraintsLabel = NSLayoutConstraint.constraintsWithVisualFormat("V:|[label]|", options: [], metrics: nil, views: views)
33-
let vConstraintsActivity = NSLayoutConstraint.constraintsWithVisualFormat("V:|[activity]|", options: [], metrics: nil, views: views)
31+
let hConstraints = NSLayoutConstraint.constraints(withVisualFormat: "|-[activity]-[label]-|", options: [], metrics: nil, views: views)
32+
let vConstraintsLabel = NSLayoutConstraint.constraints(withVisualFormat: "V:|[label]|", options: [], metrics: nil, views: views)
33+
let vConstraintsActivity = NSLayoutConstraint.constraints(withVisualFormat: "V:|[activity]|", options: [], metrics: nil, views: views)
3434

3535
centerView.addConstraints(hConstraints)
3636
centerView.addConstraints(vConstraintsLabel)

Example/ViewController.swift

+11-11
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ViewController: UIViewController, StatefulViewController {
1818
super.viewDidLoad()
1919

2020
// Setup refresh control
21-
refreshControl.addTarget(self, action: #selector(refresh), forControlEvents: .ValueChanged)
21+
refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged)
2222
tableView.addSubview(refreshControl)
2323

2424
// Setup placeholder views
@@ -29,7 +29,7 @@ class ViewController: UIViewController, StatefulViewController {
2929
errorView = failureView
3030
}
3131

32-
override func viewWillAppear(animated: Bool) {
32+
override func viewWillAppear(_ animated: Bool) {
3333
super.viewWillAppear(animated)
3434

3535
setupInitialViewState()
@@ -45,7 +45,7 @@ class ViewController: UIViewController, StatefulViewController {
4545
print("startLoading -> loadingState: \(self.lastState.rawValue)")
4646

4747
// Fake network call
48-
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(3 * Double(NSEC_PER_SEC))), dispatch_get_main_queue()) {
48+
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Double(Int64(3 * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC)) {
4949
// Success
5050
self.dataArray = ["Merlot", "Sauvignon Blanc", "Blaufränkisch", "Pinot Nior"]
5151
self.tableView.reloadData()
@@ -73,24 +73,24 @@ extension ViewController {
7373
return dataArray.count > 0
7474
}
7575

76-
func handleErrorWhenContentAvailable(error: ErrorType) {
77-
let alertController = UIAlertController(title: "Ooops", message: "Something went wrong.", preferredStyle: .Alert)
78-
alertController.addAction(UIAlertAction(title: "OK", style: .Default, handler: nil))
79-
self.presentViewController(alertController, animated: true, completion: nil)
76+
func handleErrorWhenContentAvailable(_ error: Error) {
77+
let alertController = UIAlertController(title: "Ooops", message: "Something went wrong.", preferredStyle: .alert)
78+
alertController.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))
79+
self.present(alertController, animated: true, completion: nil)
8080
}
8181

8282
}
8383

8484

8585
extension ViewController: UITableViewDataSource {
8686

87-
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
87+
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
8888
return dataArray.count
8989
}
9090

91-
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
92-
let cell = tableView.dequeueReusableCellWithIdentifier("textCell", forIndexPath: indexPath)
93-
cell.textLabel?.text = dataArray[indexPath.row]
91+
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
92+
let cell = tableView.dequeueReusableCell(withIdentifier: "textCell", for: indexPath)
93+
cell.textLabel?.text = dataArray[(indexPath as NSIndexPath).row]
9494
return cell
9595
}
9696

StatefulViewController/StatefulViewController.swift

+5-5
Original file line numberDiff line numberDiff line change
@@ -48,29 +48,29 @@ public protocol StatefulViewController: class, BackingViewProvider {
4848
/// Sets up the initial state of the view.
4949
/// This method should be called as soon as possible in a view or view controller's
5050
/// life cycle, e.g. `viewWillAppear:`, to transition to the appropriate state.
51-
func setupInitialViewState(completion: (() -> Void)?)
51+
func setupInitialViewState(_ completion: (() -> Void)?)
5252

5353
/// Transitions the controller to the loading state and shows
5454
/// the loading view if there is no content shown already.
5555
///
5656
/// - parameter animated: true if the switch to the placeholder view should be animated, false otherwise
57-
func startLoading(animated: Bool, completion: (() -> Void)?)
57+
func startLoading(_ animated: Bool, completion: (() -> Void)?)
5858

5959
/// Ends the controller's loading state.
6060
/// If an error occured, the error view is shown.
6161
/// If the `hasContent` method returns false after calling this method, the empty view is shown.
6262
///
6363
/// - parameter animated: true if the switch to the placeholder view should be animated, false otherwise
6464
/// - parameter error: An error that might have occured whilst loading
65-
func endLoading(animated: Bool, error: ErrorType?, completion: (() -> Void)?)
65+
func endLoading(_ animated: Bool, error: Error?, completion: (() -> Void)?)
6666

6767
/// Transitions the view to the appropriate state based on the `loading` and `error`
6868
/// input parameters and shows/hides corresponding placeholder views.
6969
///
7070
/// - parameter loading: true if the controller is currently loading
7171
/// - parameter error: An error that might have occured whilst loading
7272
/// - parameter animated: true if the switch to the placeholder view should be animated, false otherwise
73-
func transitionViewStates(loading: Bool, error: ErrorType?, animated: Bool, completion: (() -> Void)?)
73+
func transitionViewStates(_ loading: Bool, error: Error?, animated: Bool, completion: (() -> Void)?)
7474

7575

7676
// MARK: Content and error handling
@@ -85,5 +85,5 @@ public protocol StatefulViewController: class, BackingViewProvider {
8585
/// for the user to continue browsing content.
8686
///
8787
/// - parameter error: The error that occured
88-
func handleErrorWhenContentAvailable(error: ErrorType)
88+
func handleErrorWhenContentAvailable(_ error: Error)
8989
}

0 commit comments

Comments
 (0)