Key features in Swift
2015년 6월 11일About 1 min
Key features in Swift 관련
Swift > Article(s)
Article(s)
Key features in Swift – Hacking with Swift
Key features in Swift
I already wrote overviews of all the new features of Swift 2 and the new features in iOS 9, but I wanted to get into more depth with some of the Swift 2 language changes so you could start getting to grips with it.
So, I wrote four short articles explaining four key new features in Swift 2 syntax: try catch error handling, guard, defer and API availability checking.
You can work through them in any order you want – enjoy!
UPDATE
I put together a huge and free collection of Swift example code, so if you're upgrading your code you should definitely check it out.
- Error handling in Swift 2:
try
,catch
,do
andthrow
– it's been entirely rewritten to be modern, fast and safe, and unless you use only a small subset of the iOS APIs you're going to need to learn about it, - The
guard
keyword in Swift 2: early returns made easy –guard
takes anif
statement and adds extra optional unwrapping power, amongst other things. - The
defer
keyword in Swift 2:try
/finally
done right – if you return from a method at the end or part way through, or if you exit a method by throwing an error, your deferred work will take place. - Availability checking in Swift 2: backwards compatibility the smart way – great for using
if #available
to run version-specific code in small blocks.