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
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
170
Swift Intro
florianbuerger
1
230
Debugging & Profiling
florianbuerger
1
58
AppCode versus Xcode
florianbuerger
0
460
Other Decks in Programming
See All in Programming
色即是空、空即是色、データサイエンス
kamoneggi
1
130
Surviving Black Friday: 329 billion requests with Falcon!
ioquatix
0
3.2k
ローカルLLMでどこまでコードが書けるか / How much code can be written on a local LLM
kishida
2
380
RailsTokyo 2026#4: AI様があれば、 Hotwireの弱点は消えるか?
naofumi
3
450
空間オーディオの活用
objectiveaudio
0
160
Skillは並べた。動かなかった。契約で繋いだ。— 65個のSkillから、自走する開発サイクルへ
junholee
0
660
ビジネスモデルから紐解く、AI+型駆動開発
hirokiomote
2
540
Agentic AI & UI: Arcitecture, HITL, Emerging Standards
manfredsteyer
PRO
0
120
開発体験を左右するライブラリの API 設計 - GraphQL スキーマ構築ライブラリから考える #tskaigi
izumin5210
2
240
次世代リンターで探る、tsgo 時代における型認識カスタムルールの現実解
ytakahashii
1
410
Modding RubyKaigi for Myself
yui_knk
0
310
AIエージェントの隔離技術の徹底比較
kawayu
0
280
Featured
See All Featured
Test your architecture with Archunit
thirion
1
2.2k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
370
Build your cross-platform service in a week with App Engine
jlugia
234
18k
Visualization
eitanlees
151
17k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
What's in a price? How to price your products and services
michaelherold
247
13k
The Art of Programming - Codeland 2020
erikaheidi
57
14k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
27k
Mind Mapping
helmedeiros
PRO
1
190
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.5k
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
140
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?