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
220
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
69
Preparing for the future of API Description Languages
kylef
0
85
Resilient API Design
kylef
1
290
Building a Swift Web API and Application Together
kylef
2
1.9k
Testing without Xcode - CMD+U 2016
kylef
0
220
End-to-end: Building a Web Service in Swift (MCE 2016)
kylef
2
450
Designing APIs for Humans - Write the Docs 2016
kylef
0
280
Embracing Change - MBLTDev 2015
kylef
3
640
Practical Declarative Programming (360 iDev 2015)
kylef
3
460
Other Decks in Technology
See All in Technology
Snowflake女子会#3 Snowpipeの良さを5分で語るよ
lana2548
0
220
生成AIのガバナンスの全体像と現実解
fnifni
1
180
LINEスキマニにおけるフロントエンド開発
lycorptech_jp
PRO
0
330
レンジャーシステムズ | 会社紹介(採用ピッチ)
rssytems
0
150
5分でわかるDuckDB
chanyou0311
10
3.2k
ブラックフライデーで購入したPixel9で、Gemini Nanoを動かしてみた
marchin1989
1
520
生成AIをより賢く エンジニアのための RAG入門 - Oracle AI Jam Session #20
kutsushitaneko
4
220
10分で学ぶKubernetesコンテナセキュリティ/10min-k8s-container-sec
mochizuki875
3
330
バクラクのドキュメント解析技術と実データにおける課題 / layerx-ccc-winter-2024
shimacos
2
1k
AIのコンプラは何故しんどい?
shujisado
1
190
KubeCon NA 2024 Recap / Running WebAssembly (Wasm) Workloads Side-by-Side with Container Workloads
z63d
1
240
Microsoft Azure全冠になってみた ~アレを使い倒した者が試験を制す!?~/Obtained all Microsoft Azure certifications Those who use "that" to the full will win the exam! ?
yuj1osm
1
110
Featured
See All Featured
Documentation Writing (for coders)
carmenintech
66
4.5k
Six Lessons from altMBA
skipperchong
27
3.5k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
33
1.9k
Thoughts on Productivity
jonyablonski
67
4.4k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
2
290
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
Product Roadmaps are Hard
iamctodd
PRO
49
11k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
5
440
GraphQLとの向き合い方2022年版
quramy
44
13k
StorybookのUI Testing Handbookを読んだ
zakiyama
27
5.3k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
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