Swift
wift
They claim they focused on developers
this time..
They claim they focused on developers
this 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!

Swift

  • 1.
  • 2.
  • 3.
    They claim theyfocused on developers this time..
  • 4.
    They claim theyfocused on developers this 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
  • 5.
    Memory management? –what memory management!?
  • 6.
  • 7.
    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
  • 8.
  • 9.
    Strict • Means nouninitialized variables ( nil object reference ) • Detects and catches it on compile time • “Optional type” if something might or might not be there
  • 10.
    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.
  • 11.
    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
  • 12.
    Differences from Objective-C …waita 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()
  • 13.
    Syntax examples • letmaximumNumberOfLoginAttempts = 10 • var currentLoginAttempt = 0 • var x = 0.0, y = 0.0, z = 0.0 • println(friendlyWelcome) ..hey…psst…notice missing semicolons!
  • 14.
    Syntax examples Conditionals: if turnipsAreDelicious{ println("Mmm, tasty turnips!”) } else { println("Eww, turnips are horrible.”) } Optional: var serverResponseCode: Int? = 404
  • 15.
    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
  • 16.
  • 17.
  • 18.
    Thank you all! Andnow get back to work!