Skip to content

Commit

Permalink
Update Swift Example to Swift 3.0
Browse files Browse the repository at this point in the history
Ref #51.
  • Loading branch information
Steven-Chan committed Jun 2, 2017
2 parents ff2a104 + 350601a commit 0ba7677
Show file tree
Hide file tree
Showing 16 changed files with 400 additions and 387 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
disabled_rules:
- line_length
force_cast: warning
trailing_semicolon: error

5 changes: 3 additions & 2 deletions Example/SKYKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@
TargetAttributes = {
3813B6A41D35E62C004F4E14 = {
CreatedOnToolsVersion = 7.3;
LastSwiftMigration = 0830;
};
38A48B3F1D34E41800988B84 = {
CreatedOnToolsVersion = 7.3;
Expand Down Expand Up @@ -1049,7 +1050,7 @@
PRODUCT_BUNDLE_IDENTIFIER = "io.skygear.skykit.Swift-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Debug;
};
Expand All @@ -1071,7 +1072,7 @@
MTL_ENABLE_DEBUG_INFO = NO;
PRODUCT_BUNDLE_IDENTIFIER = "io.skygear.skykit.Swift-Example";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 2.3;
SWIFT_VERSION = 3.0;
};
name = Release;
};
Expand Down
24 changes: 12 additions & 12 deletions Example/Swift Example/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let endpoint = NSUserDefaults.standardUserDefaults().stringForKey("SkygearEndpoint")
let endpoint = UserDefaults.standard.string(forKey: "SkygearEndpoint")
if let endpointValue = endpoint {
SKYContainer.defaultContainer().configAddress(endpointValue)
SKYContainer.default().configAddress(endpointValue)
}

let apiKey = NSUserDefaults.standardUserDefaults().stringForKey("SkygearApiKey")
let apiKey = UserDefaults.standard.string(forKey: "SkygearApiKey")
if let apiKeyValue = apiKey {
SKYContainer.defaultContainer().configureWithAPIKey(apiKeyValue)
SKYContainer.default().configure(withAPIKey: apiKeyValue)
}

application.registerUserNotificationSettings(UIUserNotificationSettings(
forTypes: [.Alert, .Badge, .Sound],
types: [.alert, .badge, .sound],
categories: nil
))

return true
}

func application(application: UIApplication, didRegisterUserNotificationSettings notificationSettings: UIUserNotificationSettings) {
func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
guard !notificationSettings.types.isEmpty else {
print("User does not allow notification")
return
Expand All @@ -54,18 +54,18 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
application.registerForRemoteNotifications()
}

func application(application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: NSData) {
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
print("Successfully registered remote notification")

let skygear = SKYContainer.defaultContainer()
let skygear = SKYContainer.default()
guard skygear.currentUser != nil else {
print("User not yet login, abort registering device")
return
}

skygear.registerDeviceWithDeviceToken(deviceToken) { (deviceID, error) in
skygear.registerDevice(withDeviceToken: deviceToken) { (deviceID, error) in
guard error == nil else {
print("Failed to register device: \(error.localizedDescription)")
print("Failed to register device: \(error?.localizedDescription)")
return
}

Expand All @@ -77,7 +77,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}

func application(application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: NSError) {
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
print("Failed to register remote notification: \(error.localizedDescription)")
}
}
2 changes: 1 addition & 1 deletion Example/Swift Example/Predicate/PickerTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class PickerTableViewCell: UITableViewCell {
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TextFieldTableViewCell: UITableViewCell {
// Initialization code
}

override func setSelected(selected: Bool, animated: Bool) {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)

// Configure the view for the selected state
Expand Down
20 changes: 10 additions & 10 deletions Example/Swift Example/View Controllers/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ class MainViewController: UITableViewController {

var hasPromptedForConfiguration: Bool {
get {
return NSUserDefaults.standardUserDefaults().boolForKey("HasPromptedForConfiguration")
return UserDefaults.standard.bool(forKey: "HasPromptedForConfiguration")
}
set {
NSUserDefaults.standardUserDefaults().setBool(newValue, forKey: "HasPromptedForConfiguration")
NSUserDefaults.standardUserDefaults().synchronize()
UserDefaults.standard.set(newValue, forKey: "HasPromptedForConfiguration")
UserDefaults.standard.synchronize()
}
}

Expand All @@ -39,16 +39,16 @@ class MainViewController: UITableViewController {
if !self.hasPromptedForConfiguration {
let alert = UIAlertController(title: "Configuration Required",
message: "The app does not know how to connect to your Skygear Server. Configure the app now?",
preferredStyle: .Alert)
alert.addAction(UIAlertAction(title: "Ignore", style: .Cancel, handler: { (action) in
preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Ignore", style: .cancel, handler: { (_) in
self.hasPromptedForConfiguration = true
}))
alert.addAction(UIAlertAction(title: "Configure", style: .Default, handler: { (action) in
alert.addAction(UIAlertAction(title: "Configure", style: .default, handler: { (_) in
self.hasPromptedForConfiguration = true
self.performSegueWithIdentifier("server_configuration", sender: self)
self.performSegue(withIdentifier: "server_configuration", sender: self)
}))
alert.preferredAction = alert.actions.last
self.presentViewController(alert, animated: true, completion: nil)
self.present(alert, animated: true, completion: nil)
}

}
Expand All @@ -60,9 +60,9 @@ class MainViewController: UITableViewController {

// MARK: - Navigation

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "create_record" {
let controller = segue.destinationViewController as! RecordViewController
let controller = segue.destination as! RecordViewController
controller.creatingNewRecord = true
}
}
Expand Down
Loading

0 comments on commit 0ba7677

Please sign in to comment.