Top Banner
Swift
18

Swift

Jul 16, 2015

Download

Internet

scandiweb
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Swift

Swift

Page 2: Swift

wift

Page 3: Swift

They claim they focused on developersthis time..

Page 4: Swift

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

Page 5: Swift

Memory management? – what memory management!?

Page 6: Swift

Faster than C

Page 7: Swift

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

Page 8: Swift

Strict

Page 9: Swift

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

Page 10: Swift

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.

Page 11: Swift

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

Page 12: Swift

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()

Page 13: Swift

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!

Page 14: Swift

Syntax examples

Conditionals:

if turnipsAreDelicious {println("Mmm, tasty turnips!”)

} else {println("Eww, turnips are horrible.”)

}

Optional:var serverResponseCode: Int? = 404

Page 15: Swift

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

Page 16: Swift

Objective-C

Page 17: Swift

Interactive Playgrounds

Page 18: Swift

Thank you all!And now get back to work!