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
Swift 2 in Production
Search
Florian
November 17, 2015
Programming
79
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swift 2 in Production
Talk held at our local user group,
http://mobilemaultaschen.de
Florian
November 17, 2015
More Decks by Florian
See All by Florian
[iOS] dependency management
florianbuerger
0
79
Dem Fehler auf der Spur - Mobile Testing Days 2015
florianbuerger
0
85
WatchKit overview
florianbuerger
0
180
Swift Intro
florianbuerger
1
230
Debugging & Profiling
florianbuerger
1
63
AppCode versus Xcode
florianbuerger
0
460
Other Decks in Programming
See All in Programming
過去最大のMCPアップデート! 2026-07-28 RC版の謎に迫る
licux
6
450
トークンをケチるな、設計しろ:GitHub Copilotを賢く使うコンテキスト戦略
ochtum
0
290
コンテキストの使い捨てをやめる — ビジネスルール駆動開発と miko —
ioki
0
270
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
200
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
640
TAKTでAI駆動開発の品質を設計する
j5ik2o
7
1.7k
SREは、MCPとSRE Agentをこう使え!
kazumax55
0
140
ローカルLLMでどこまでコードが書けるか -縮小版 / How much code can be written on a local LLM Shortened
kishida
2
170
エンジニアにデザインハーネスを 〜デザインプロセスを規定するためのハーネス〜 / Design harness from an engineer's perspective
rkaga
2
730
アルゴリズムは何を圧縮しているのか ─ Haskell から育った「圧縮代数」というメンタルモデル
naoya
13
2.3k
ECSアプリログをFireLensでコスト削減しようとしたけど諦めた話 in Fargate×Node.js
akihisaikeda
2
4.2k
Generative UI & AI-Assistants for Your Angular Solutions
manfredsteyer
PRO
0
130
Featured
See All Featured
Designing Powerful Visuals for Engaging Learning
tmiket
1
440
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
49
10k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.4k
The Cost Of JavaScript in 2023
addyosmani
55
10k
AI in Enterprises - Java and Open Source to the Rescue
ivargrimstad
0
1.4k
Future Trends and Review - Lecture 12 - Web Technologies (1019888BNR)
signer
PRO
0
3.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
The Illustrated Guide to Node.js - THAT Conference 2024
reverentgeek
1
410
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
1
370
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
287
14k
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
380
A Soul's Torment
seathinner
6
3k
Transcript
Swift 2 In Production
New Stuff ☞ guard ♥♥♥ ☞ #available() ♥ ☞ Protocol
Extensions ♥♥ ☞ SDK ♥ ☞ Error Handling " ☞ defer "
guard ☞ no more pyramid of doom optionals if let
a = a { if let b = b { if let c = c { fn(a, b, c) } } }
guard ☞ better, but still pretty unreadable ☞ still too
much indentation if let a = a, let b = b, let c = c { fn(a, b, c) }
guard guard let a = a else { Log.Error("a is
required at this point.") return } guard let b = b else { Log.Error("b is required at this point.") return } guard let c = c else { Log.Error("c is required at this point.") return }
#available() let iOS9 = NSOperatingSystemVersion( majorVersion: 9, minorVersion: 0, patchVersion:
0) if NSProcessInfo().isOperatingSystemAtLeastVersion(iOS9) { // Stack views ! }
#available() if #available(iOS 9, *) { // Stack views !
} else { // Stack views " } @available(iOS 9, *) class MyStackView: UIStackView {}
Protocol extensions ☞ replace base class ☞ default behaviour ☞
decoration/composition ☞ adopt in enum/struct/class
Protocol extensions @objc public protocol Bookmarkable { var remoteIdentifier: Int
{ get } } extension Bookmarkable { public var remoteIdentifier: Int { return -1 } }
Protocol Extensions extension NSManagedObject: Bookmarkable { public var remoteIdentifier: Int
{ guard respondsToSelector("remoteID") else { Log.Warn("\(self) doesn't respond to 'remoteID'") return -1 } guard let remoteID = valueForKey("remoteID") as? NSNumber else { Log.Error("'remoteID' didn't return a number.") return -1 } return Int(remoteID.integerValue) } }
Error handling ☞ good ol' times var readError: NSError? let
contents = NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding, error: &readError) if readError != nil { // Oh no, something went wrong }
Error handling ☞ the new way: let contents: NSString? do
{ contents = try NSString(contentsOfFile: filePath, encoding: NSUTF8StringEncoding) } catch let error as NSError { print(error) }
Error handling ☞ define your error types enum FileError: ErrorType
{ case NoSuchFile case IsDirectory } func readFile(atPath path: String) throws { var isDir: ObjCBool = false guard NSFileManager().fileExistsAtPath(path, isDirectory: &isDir) else { throw FileError.NoSuchFile } guard isDir.boolValue == false else { throw FileError.IsDirectory } }
Error handling do { try readFile(atPath: "~/.vim") } catch FileError.NoSuchFile
{ print("No such file") } catch FileError.IsDirectory { print("Item at path is a directory") }
defer func writeToStream(something: StreamWriteable) { let stream = openStream() defer
{ closeStream(stream) } something.write(toStream: stream) // don't worry about closing it // even when errors occur }
Mixed Projects ☞ Setup ☞ bridging Header (only app targets)
☞ module map (framework targets) ☞ module name (requires DEFINES_MODULE=YES)
Mixed Projects ☞ Ignore Xcode "Can't build module XYZ" ☞
Ignore missing auto completion when importing "ModuleName- Swift.h"
Debugger ☞ Can't jump into ObjC file from Swift code
☞ Can't jump into Swift file from ObjC code
Dependencies ☞ Dependency management, iOS >= 8.0 ☞ CocoaPods →
use_frameworks! ☞ Carthage ☞ Dependency management, iOS < 8.0 ☞ Include source files ☞ git submodules !
Other Annoyances ☞ Quick open from Swift file ☞ NO
REFACTORING!!!111elf !
Future? Objective-C == techn. dept?