Blog

Upgrade to iOS 10 now, pre-requisites, steps

IOS 10 upgrade
First let me clarify one thing iOS 10 upgrade means here upgradation of code from swift 2 to swift 3 and Xcode version from 7 to 8. Coming to pre-requisites there aren’t any except a proper functioning swift code and Xcode 8 setup in your system.

Before coming to steps let me ask you a question. why?
Is it really necessary to upgrade our properly functioning code from swift 2 to swift 3?
Well it depends our requirements for the app.

Let me put out a few examples –
In case of sample application we need notification overriding feature which is available in iOS 10 due to added UNNotificationServiceExtension framework and also the UIUserNotificationSettings and UIUserNotificationAction etc, some of the notification frameworks have been deprecated in iOS10 .So we upgraded the app.

Similarly if your app uses any framework which is deprecated in iOS 10 and if your app has future scope or features yet to be done its better that we upgrade the code, else if your app is stagnant then no need to upgrade.

Next coming to how?
Xcode 8.0 comes with a Swift Migrator tool that helps you migrate your project to Swift 3, or update it to work with Swift 2.3 and the new SDKs.
When you open your project with Xcode 8.0 for the first time, you will be prompted via the migration assistant to do a migration pass. The assistant can also be invoked manually from the menu Edit -> Convert -> To Current Swift Syntax
After you invoke the migration assistant and you select “Use Swift 2.3” or “Use Swift 3”, you will be presented with a list of targets to migrate. Targets that do not contain any Swift code will not be selected.
Clicking ‘Next’ will bring up the ‘Generate Preview’ sheet and the assistant will initiate a migration ‘build’ to get source changes. When this is done, you will be presented with all the changes that will be applied once you click on ‘Save’. Note that in the diff view, the original source (before conversion) is on the right and the changes are on the left. Clicking ‘Save’ will apply the source changes to the original files

Xcode converts but you will be left with some of the changes you need to do manually for which you need to know code changes in swift 3
The biggest update in Swift 3 involves the standard library adopting consistent naming conventions across libraries.

Some of the changes in Swift 3 are

Consistent First Argument Labels
Till now in swift we have the habit of omitting the label of first argument in functions and methods but it’s compulsory now
Eg- NSJSONSerialization.JSONObjectWithData(data, options: []) => JSONSerialization.jsonObject(with: data, options: [])
array.removeAtIndex(3) => array.remove(at: 3)
For methods without any need of label and well readable we should place a underscore in the place of first label
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { … }

Omit needless words
In previous versions of Swift, methods name are more elaborative including return types, but due to compiler’s type checking ability these extra naming has been removed in swift 3
helloString.stringByAppendingString(“world”) => helloString.appending(“world”)
animals.insert(“Koala”, atIndex: 0) => animals.insert(“Koala”, at: 0)

Capitalization on Enumeration Cases
UIStatusBarStyle.LightContent => UIStatusBarStyle.lightContent

Methods that Return or Modify
A noun (includes suffix like -ed or -ing)method returns a value
A verb method performs the action on referenced memory
ages.sort() // modifies original ages array
let newAges = ages.sorted()

Inline Sequences
sequence(first:next:) and sequence(state:next:) are global functions that return infinite sequences.
They take a initial value and lazily apply a closure
for x in sequence(first: 0.1, next: { $0 * 2 }).prefix(while: { $0 < 4 }) { // 0.1, 0.2, 0.4, 0.8, 1.6, 3.2 } • Modernized GCD and Core Graphics
The Grand Central Dispatch and Core Graphics are written in C and in swift 2 used C style API, but now it’s reimagined to native Swift
let queue = dispatch_queue_create(“com.test.myqueue”, nil)
dispatch_async(queue) {
print(“Hello World”)
}

// new way, Swift 3
let queue = DispatchQueue(label: “com.test.myqueue”)
queue.async {
print(“Hello World”)
}

Swift Standard Library
One example is the Collection indexing model has been changed drastically from swift 2 to swift 3
myIndex.successor() => myCollection.index(after:myIndex)

Changes with handling of implicitly unwrapped optionals
Closures are made non escaping by default where as in swift 1 and swift 2 they are escaping by default

Performance improvements have been made in Xcode 8
Automation tool of instruments which is used to write automation tests in javascript has been deprecated in Xcode 8. Now we have to write UI tests in Swift using Xcode UITesting.

References
https://swift.org/migration-guide/
https://www.raywenderlich.com/135655/whats-new-swift-3

By – Gorla Uhasree, Software Engineer

adminUpgrade to iOS 10 now, pre-requisites, steps
Share this post

Join the conversation

Related Posts