Swift
Swift
wift
They claim they focused on developersthis time..
They claim they focused on developersthis time..
• Built specifically for iOS and MAC app development• You can do the same things as with Objective-C• Add great features from the other languages such
as tuples and optionals• Less brackets and semicolons!!!• Looks and feels like scripting language ( Javascript )
…so, we got LESS code to write and FAST development times
Memory management? – what memory management!?
Faster than C
Faster than C
• Because of optimizations you can do with Swift that is very difficult to do with C ( not a developer’s written optimization )
• Swift by design is well optimized
Strict
Strict
• Means no uninitialized variables ( nil object reference )
• Detects and catches it on compile time
• “Optional type” if something might or might not be there
Similarities to Objective-C
• Basic numeric types (Int, UInt, Float, Double)• Most C operators are carried over to Swift, but there are some new
operators• Curly braces are used to group statements.• Variables are assigned using an equals sign, but compared using
two consecutive equals signs. A new identity operator, ===, is provided to check if two data elements refer to the same object.
• Square brackets are used with arrays, both to declare them and to get a value at a given index in one of them.
• Control statements, for, while, if, switch are similar, but have extended functionality, e.g. a for in that iterates over any collection type, a switch that takes non-integer cases, etc.
• Class methods are inherited, just like instance methods; self in class methods is the class the method was called on.
Differences from Objective-C
• Statements do not need to end with a semicolon (;), though they must be used to allow more than one statement on a line
• Strong typing
• No exception handling
Differences from Objective-C
…wait a minute, no exception handling?
Yes, no catch / try blocks but you can still utilize Objective-C..and throw exception with NSExceptions
Networking uses good ol’:success/ failure callbacks
But suggested method is to use assert()
Syntax examples
• let maximumNumberOfLoginAttempts = 10
• var currentLoginAttempt = 0
• var x = 0.0, y = 0.0, z = 0.0
• println(friendlyWelcome)
..hey…psst…notice missing semicolons!
Syntax examples
Conditionals:
if turnipsAreDelicious {println("Mmm, tasty turnips!”)
} else {println("Eww, turnips are horrible.”)
}
Optional:var serverResponseCode: Int? = 404
Syntax examples
• Assert() used for debugging purposes:
let age = -3
assert(age >= 0, "A person's age cannot be less than zero")
assertion is an effective way to ensure that such conditions are highlighted and noticed during development, before your app is published
Objective-C
Interactive Playgrounds
Thank you all!And now get back to work!