Upgrade to PRO for Only $50/Year—Limited-Time Offer! 🔥
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Swift Workshop
Search
puls
June 10, 2014
Technology
2
340
Swift Workshop
What you need to know about Apple's new language.
puls
June 10, 2014
Tweet
Share
More Decks by puls
See All by puls
Introductory Version Control with Git
puls
6
130
Other Decks in Technology
See All in Technology
Oracle Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
2
170
AI-DLCを現場にインストールしてみた:プロトタイプ開発で分かったこと・やめたこと
recruitengineers
PRO
2
220
Snowflake導入から1年、LayerXのデータ活用の現在 / One Year into Snowflake: How LayerX Uses Data Today
civitaspo
0
1.5k
AgentCore BrowserとClaude Codeスキルを活用した 『初手AI』を実現する業務自動化AIエージェント基盤
ruzia
7
750
MySQLとPostgreSQLのコレーション / Collation of MySQL and PostgreSQL
tmtms
1
1.1k
Oracle Database@Google Cloud:サービス概要のご紹介
oracle4engineer
PRO
1
740
MLflowダイエット大作戦
lycorptech_jp
PRO
1
160
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
9.8k
障害対応訓練、その前に
coconala_engineer
0
150
アプリにAIを正しく組み込むための アーキテクチャ── 国産LLMの現実と実践
kohju
0
170
S3を正しく理解するための内部構造の読解
nrinetcom
PRO
3
230
20251219 OpenIDファウンデーション・ジャパン紹介 / OpenID Foundation Japan Intro
oidfj
0
390
Featured
See All Featured
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
21
1.3k
KATA
mclloyd
PRO
33
15k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.8k
Building Flexible Design Systems
yeseniaperezcruz
330
39k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
64
Un-Boring Meetings
codingconduct
0
160
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.1k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
47
33k
Facilitating Awesome Meetings
lara
57
6.7k
Lessons Learnt from Crawling 1000+ Websites
charlesmeaden
0
940
[SF Ruby Conf 2025] Rails X
palkan
0
550
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
9
1k
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