handybook : swift

14
Handybook : Swift Jayant Sani

Upload: sonia-alvarado

Post on 03-Jan-2016

21 views

Category:

Documents


0 download

DESCRIPTION

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, - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Handybook : Swift

Handybook: Swift

Jayant Sani

Page 2: Handybook : Swift
Page 3: Handybook : Swift
Page 4: Handybook : Swift
Page 5: Handybook : Swift
Page 6: Handybook : Swift

Handybook Opinions• “It’s like Ruby on Rails, for iOS!” – Nikita

• “A function should only do one thing and return one value” - Justin

Page 7: Handybook : Swift

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

Page 8: Handybook : Swift

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)

Page 9: Handybook : Swift

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*

Page 10: Handybook : Swift

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

Page 11: Handybook : Swift

Guess what returns

Page 12: Handybook : Swift

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 }

Page 13: Handybook : Swift

Generics

Extensions

Tuples

Page 14: Handybook : Swift

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