Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
A Swift Approach (Warsaw 2014)
Search
Kyle Fuller
November 27, 2014
Technology
4
240
A Swift Approach (Warsaw 2014)
Kyle Fuller
November 27, 2014
Tweet
Share
More Decks by Kyle Fuller
See All by Kyle Fuller
Design APIs and deliver what you promised
kylef
0
130
Preparing for the future of API Description Languages
kylef
0
120
Resilient API Design
kylef
1
340
Building a Swift Web API and Application Together
kylef
2
2.1k
Testing without Xcode - CMD+U 2016
kylef
0
270
End-to-end: Building a Web Service in Swift (MCE 2016)
kylef
2
490
Designing APIs for Humans - Write the Docs 2016
kylef
0
350
Embracing Change - MBLTDev 2015
kylef
3
690
Practical Declarative Programming (360 iDev 2015)
kylef
3
530
Other Decks in Technology
See All in Technology
pool.ntp.orgに ⾃宅サーバーで 参加してみたら...
tanyorg
0
1.7k
Amazon Rekognitionで 「信玄餅きなこ問題」を解決する
usanchuu
1
100
Embedded SREの終わりを設計する 「なんとなく」から計画的な自立支援へ
sansantech
PRO
3
2.7k
AI駆動開発を事業のコアに置く
tasukuonizawa
1
440
(技術的には)社内システムもOKなブラウザエージェントを作ってみた!
har1101
0
370
[CV勉強会@関東 World Model 読み会] Orbis: Overcoming Challenges of Long-Horizon Prediction in Driving World Models (Mousakhan+, NeurIPS 2025)
abemii
0
160
20260208_第66回 コンピュータビジョン勉強会
keiichiito1978
0
210
SchooでVue.js/Nuxtを技術選定している理由
yamanoku
3
270
こんなところでも(地味に)活躍するImage Modeさんを知ってるかい?- Image Mode for OpenShift -
tsukaman
1
180
プレビュー版のDevOpsエージェントを現段階で触ってみた
ad_motsu
1
110
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
570
AIエージェントに必要なのはデータではなく文脈だった/ai-agent-context-graph-mybest
jonnojun
1
260
Featured
See All Featured
Making Projects Easy
brettharned
120
6.6k
So, you think you're a good person
axbom
PRO
2
1.9k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
61
52k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
120
RailsConf 2023
tenderlove
30
1.3k
My Coaching Mixtape
mlcsv
0
52
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
9.6k
Crafting Experiences
bethany
1
57
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
430
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Reality Check: Gamification 10 Years Later
codingconduct
0
2k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.2k
Transcript
A SWIFT APPROACH KYLEFULLER
KYLEFULLER
None
None
NEW CONCEPTS
RUNTIME
@objc / NSObject
NSKeyValueObserving
RUNTIME
WWDC 2015
OPTIONALS?
func compute() -> Bool?
true false neither
LACK OF A VALUE
NOT AN EMPTY VALUE
CAN'T WE DO THIS IN OBJECTIVE-C?
nil Nil NULL CGRectNull -1 0 NSNotFound NSNull ...
EXPRESS YOU DON'T ACCEPT NIL
EXPRESS YOU WILL NOT RETURN NIL
/// You **MUST** pass in a URL - (instancetype)initWithURL:(NSURL *)URL
{ NSParameterAssert(URL != nil); }
- (UITableViewCell *)tableView:(UITableView *)tv cellForRowAtIndexPath:(NSIndexPath *)path { return nil; }
None
RUNTIME ERROR
RUNTIME ERROR
COMPILE ERROR
None
TUPLES
func get(username:String) -> (Person?, NSError?)
let person, error = get("Kyle")
OBJECTIVE-C
NSError *error; Person *person = [Person getPerson:@"Kyle" error:&error];
NAMED TUPLES
func get(username:String) -> (person:Person?, error:NSError?)
let result = get("Kyle") result.person result.error
- (NSArray *)getPerson:(NSString *)username; - (NSDictionary *)getPerson:(NSString *)username;
NSDictionary *components = [Person getPerson:@"kyle"]; Person *person = components["person"]; NSError
*error = components["error"];
TYPE SAFETY?
FRAGILE
ENUMERATIONS
enum Result { case Success(String) case Error(Error) }
switch result { case .Error(let error): println("There was an error
(\(error)).") case .Success(let string): println("\(string)") }
CLOSURES
EVERYTHING IS A CLOSURE
class TestObject { func testA() -> () { println("first test")
} var testB:(() -> ()) = { println("second test") } }
let testing = TestObject() testing.testA() testing.testB()
testing.testB = testing.testA
testing.testB() // Actually calls testA
CONSISTENCY
FUNCTIONAL
None
let string = "Hello World" let matches:[NSTextCheckingResult] = /* regex
for words in string */ matches.map { string.substringWithRange($0.range) }
let string = "Hello World" let matches:[NSTextCheckingResult] = /* regex
for words in string */ var strings = [String]() for match in matches { let catch = string.substringWithRange(match.range) strings.append(catch) }
func reduce(initial, combine) -> result
combine : ((previous, current) -> (result))
let items = [["a", "b"], ["c", "d"], ["e"]] items.reduce([]) {
initial, expressions -> [String] in initial + expressions } => ["a", "b", "c", "d", "e"]
let items = [["a", "b"], ["c", "d"], ["e"]] items.reduce([], +)
=> ["a", "b", "c", "d", "e"]
func +<T>(lhs:[T], rhs:[T]) -> [T]
items.sort { $0 > $1 }
items.sort(>)
items.filter { $0.hasPermission }
func isAdmin(user:User) -> Bool { return user.username == "Kyle" }
users.filter(isAdmin)
GENERICS
Array<String>
Dictionary<String, Int>
func max<T : Comparable>(a:T, b:T) -> T { return a
> b ? a : b }
max(anInteger, anotherInteger) max(aFloat, anotherFloat) max(aString, anotherString)
PATTERN MATCHING
let point = (1, 2) switch point { case (0,
0): println("(0, 0) is at the origin.") case (-2...2, -2...2): println("(\(point.0), \(point.1)) is near the origin.") default: println("The point is at (\(point.0), \(point.1)).") } // prints "(1, 2) is near the origin."
@auto_closure
delay(5, println("Hello World"))
func delay(time:UInt32, block:@auto_closure) { sleep(time) block() }
BUILDING ASSERT() IN SWIFT
assert(someExpensiveComputation() != 42)
func assert(predicate : () -> Bool) { #if !NDEBUG if
!predicate() { abort() } #endif }
PLAYGROUNDS
PLAYGROUNDS
SWIFT
SAFER
CONVENTIONS
CONVENTIONS
LANGUAGE CONSTRAINTS
BETTER CODE
BETTER DEVELOPERS
LESS BUGS
WE'RE ALL BEGINNERS
PERFECTING
BREAKING CHANGES
- Xcode 6.1 + Xcode 6.1.1
FOR GOOD, NOT EVIL
!
FILE RADARS
FUTURE
COMMON DESIGN PATTERNS
KYLEFULLER