Handybook : Swift
-
Upload
sonia-alvarado -
Category
Documents
-
view
27 -
download
0
description
Transcript of Handybook : Swift
Handybook: Swift
Jayant Sani
Handybook Opinions• “It’s like Ruby on Rails, for iOS!” – Nikita
• “A function should only do one thing and return one value” - Justin
Brief History• 1983: Objective-C is created• 2000: Chris Lattner starts to work on LLVM,
a compiler for Objective-C during college• 2007: LLVM project releases Clang• 2010: Lattner begins working on Swift• 2012: Apple ditches GCC, giving LLVM more
flexibility• 2014: Apple announces Swift at WWDC
High-Level Overview• Objective-C showing age – Smalltalk syntax
o Around since the 1980s
• Many modifications to make it modern• Compile time vs Runtime (Static and dynamic)
Modern Language Features
• No semicolons!• Static type system• Optional types• Functional Programming• Closures• Tuples• Generics• Automatic Reference Counting• Extensions• REPL (Playgrounds)• Designated and Convenience Initializers*
Static Type System• Objective-C: Dynamic Typing, only object type
was (id) in early stagesValid Objective-C code:NSString *string = @”Handybook”;id str = stringNSDictionary *dict= str;dict[@”name”]- Compiles fine, runtime error
• Swift: Static Typing
Guess what returns
Functional • Objective-C: Blocks• F*ckingblocksyntax.comreturnType (^blockName)(parameterTypes) = ^returnType(parameters) { statements };
• Swift: Functions are first class objects, Closures(param1Type, param2Type, …) -> returnType{ (params) -> returnType in statements }
Generics
Extensions
Tuples
Drawbacks• Xcode 6 is very, very, very buggy – beta• Proprietary• Operator overloading – controversial• No pointers – errors, functions• Dealing with JSON Data• Message passing vs. vtable• Vague constants – “let” keyword• No access modifiers• Objective-C without Smalltalk