Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Swift Workshop
Search
puls
June 10, 2014
Technology
360
2
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swift Workshop
What you need to know about Apple's new language.
puls
June 10, 2014
More Decks by puls
See All by puls
Introductory Version Control with Git
puls
6
150
Other Decks in Technology
See All in Technology
Rustuna: Rustによる高速なOptuna実装
pfn
PRO
0
190
日本語に強いオープンな大規模言語モデル「LLM-jp」
odashi
4
1.1k
継続的なAIコスト最適化
bgpat
1
340
AI導入は済んだ。次は統制を作り替える番だ_AI×開発組織 Summit 2026
techtekt
PRO
0
220
QA4AI 2026-Oct 生成AI時代の品質保証
tokuty
1
860
実体験から学ぶ分析エージェントの開発と運⽤
recruitengineers
PRO
8
2.4k
Refining Active Record
shugo
0
150
AI コーディングと人間の認知スループット / CTO Night & Day 2026 Morning Session / AI Coding and Human Cognitive Throughput
prog893
4
1.1k
20261017福岡devIO 「AIは"良いダッシュボード"を作れるか?
jtakeda
0
150
Rust で関数型ドメインモデリング
takonda
0
140
Conditional PED-ANOVA: Hyperparameter Importance in Hierarchical & Dynamic Search Spaces
pfn
PRO
0
130
⾮構造化データを価値に変える AI エージェント基盤とその組織
ivry_presentationmaterials
0
190
Featured
See All Featured
How Software Deployment tools have changed in the past 20 years
geshan
2
35k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
Accessibility Awareness
sabderemane
1
250
Docker and Python
trallard
47
4.2k
Technical Leadership for Architectural Decision Making
baasie
3
600
Information Architects: The Missing Link in Design Systems
soysaucechin
1
1.2k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
3k
State of Search Keynote: SEO is Dead Long Live SEO
ryanjones
0
320
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.7k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Producing Creativity
orderedlist
PRO
348
41k
Transcript
Swift Workshop June 10th, 2014
None
3 Swift is quite like Objective-C.
Native on iOS and OS X
Full support for all Cocoa and low-level APIs
Xcode- and LLVM-based workflow
Seamless bridging to Objective-C
Automatic Reference Counting
Named method parameters
Classes, Structs, Protocols, Enums
Closures
Int / Int32 / Int64 / UInt / UInt32 /
UInt64
if / for / while / do…while / switch
Swift is quite unlike Objective-C.
Not a superset of C
override func
Range operator
Range operator for i in 1..3 { print(i) } //
prints 12 for i in 1...3 { print(i) } // prints 123
Getters and setters
class Person { var firstName : String = "" var
lastName : String = "" var fullName : String { get { return "\(firstName) \(lastName)" } set { let parts = newValue.componentsSeparatedByString(" ") firstName = parts[0] lastName = parts[1] } } } Getters and setters
No default fallthrough on switch
Static type system
enum ComparisonResult { case Ascending case Equal case Descending }
! typealias Comparator = (Int, Int) -> ComparisonResult func sortArray(array : Int[], compareFunction : Comparator) { // ... } Static type system
Generics
enum ComparisonResult { case Ascending case Equal case Descending }
! func sortArray<T>(array : T[], compareFunction : (T, T) -> ComparisonResult) { // ... } Generics
Parameterized Enums
enum FlightStatus { case OnTime // Sweet case Delayed(Int) //
Oh well case UnitedAirlines // Should have known } Parameterized Enums
Structs with behavior
struct Rect { let height : Double let width :
Double var area : Double { return height * width } } ! let r = Rect(height: 4, width: 8) r.area // 32.0 Structs with behavior
Tuples
Pattern Matching
let a : Any = 124 let b = 346
! switch (a, b) { case (_, 345): println("b is 345") case (is Int, _): println("a is Int") default: println("nothing matched") } Pattern Matching
Constants and variables
let a = 1 var b = 2 b =
3 a = 3 // error ! let c = [1,2,3] // fixed-size array var d = [1,2,3] // mutable array c += 4 // error d += 4 ! c[1] = 4 // this works, though Constants and variables
Default parameter values
func madLibs(a : String, b : String = "Second", c
: String = "Third") { println("\(a) then \(b) then \(c)") } madLibs("foo", b: "bar", c: "baz") madLibs("yep") Default parameter values
Operator overloading
Subscripting
extension Int { subscript(index : Int) -> Int { get
{ return self % index } } } Subscripting
Value types
“Trailing closure” syntax
extension Int { func times(closure : () -> ()) {
for _ in 0..self { closure() } } } ! 3.times() { println("Swift is the best!") } “Trailing closure” syntax
Syntactic sugar
var numbers = [1,5,2,9,3,4,6,8,7] Syntactic sugar
var numbers = [1,5,2,9,3,4,6,8,7] numbers.sort({ a, b in a <
b }) Syntactic sugar
var numbers = [1,5,2,9,3,4,6,8,7] numbers.sort({ a, b in a <
b }) numbers.sort { a, b in a < b } Syntactic sugar
var numbers = [1,5,2,9,3,4,6,8,7] numbers.sort({ a, b in a <
b }) numbers.sort { a, b in a < b } numbers.sort { $0 < $1 } Syntactic sugar
var numbers = [1,5,2,9,3,4,6,8,7] numbers.sort({ a, b in a <
b }) numbers.sort { a, b in a < b } numbers.sort { $0 < $1 } numbers.sort(<) Syntactic sugar
Optionals
var a : Int? var b : Int ! a
// nil a = 1 // {Some 1} a + 2 // this is an error a! + 2 // 3 b = 2 // 2 b + 2 // 4 Optionals
Playgrounds
Practical Swift
Value types vs. Reference types
Structs vs. Classes
Array vs. NSArray
array.unshare()
http://terribleswiftideas.tumblr.com
http://developer.apple.com/swift
None
None