iOS 9, OSX El Capitan and Swift 2.0

Today Apple announced a bunch of new features and made us developers really happy. We’ve got a lot to explore, to try out and see whats possible with the latest API’s. My first WWDC and first Keynote experience were great. Entering the queue at 6am was early enough to get a nice spot in the main room.

Many blogs post about iOS 9 and OSX El Capitan, but I want to focus on my perspective as an iOS developer. Things have changed, improved, and reduced development time. But on the other side, many new things to implement in our application which takes a lot more time. Let’s walk through the things which made me feel happy.

Open sourcing Swift

Swift 2.0 will be open source. I can’t wait to see the benefits of this major decision. Bugs getting fixed faster and maybe even a way to build for Android.

Protocol improvements

Protocol extensions

You can now create protocol extensions, which saves a lot of code. It allows you to define behaviour on protocols themselves, rather than in each type’s individual conformance or in a global function.

Default protocol implementations

Something I’ve encountered a lot during my Swift projects. Sometimes you just want to have a method to be available for protocols, changeable for some or default for others.

In this example you create a default ‘asPrettyText’ method, which by default just returns asText() but can be overwritten.

extension PrettyTextRepresentable  {
    func asPrettyText() -> String {
        return asText()
    }
}

Protocol extension constraints

In Swift 1.2 you would’ve probably created global functions or copies of methods each time to create Array typed specific methods. With protocol extension constraints it’s possible to create extensions for Arrays containing objects of a specific protocol.

extension CollectionType where Generator.Element : TextRepresentable {
    func asList() -> String {
        return "(" + ", ".join(map({$0.asText()})) + ")"
    }
}

Early exit

Swift 1.2 already saved us from many if statements, but with Swift 2.0 this even gets better. In many methods you would probably start with casting to let’s before entering the main method. Swift 2.0 introduces early exiting to check wether a certain condition is true before continuing.

func greet(person: [String: String]) {
    guard let name = person["name"] else {
        return
    }

    print("Hello \(name)!")

    guard let location = person["location"] else {
        print("I hope the weather is nice near you.")
        return
    }

    print("I hope the weather is nice in \(location).")
}

greet(["name": "John"])
// prints "Hello John!"
// prints "I hope the weather is nice near you."
greet(["name": "Jane", "location": "Cupertino"])
// prints "Hello Jane!"
// prints "I hope the weather is nice in Cupertino."

UI Testing integrated

Xcode 7 integrates UI testing in a great way. It seems to be very easy to write quick UI testing, which should make it easier to adapt.
xCode UI Testing

Storyboard references

Although it’s not yet supported for Apple Watch extensions, it’s really welcome to use in our main projects. Especially big projects are getting complicated Storyboards and lose their overview. I’m very happy with this feature to separate sections of apps.

iOS 9 TestFlight support

Contrary to the latests beta versions, it will be possible to distribute apps with iOS 9 beta support through TestFlight. So use your great testers and get iOS 9 support even better and quicker.

Develop on device with a free account

This is great for the future. The fact developers can start deploying apps on their device without paying for a developer account can increase the amount of young developers in my opinion. A great step from Apple to invest a bit for future!

A small recap

It’s been a long day with way to much information to share. These are just a few topics I wanted to point out, but there’s a lot more. I especially enjoyed reading the Swift 2.0 document revision history, as you get detailed information about Swift 2.0 features combined with code examples. Tomorrow I’ll bring my MacBook to Moscone, with hopefully a recap about the new Xcode later that day!

 

Antoine van der Lee

Dutch iOS developer at Triple. Developed apps like Buienradar, Videoland and Pop the Dots.

 
Follow on Feedly