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
0
71
Swift 2 in Production
Talk held at our local user group,
http://mobilemaultaschen.de
Florian
November 17, 2015
Tweet
Share
More Decks by Florian
See All by Florian
[iOS] dependency management
florianbuerger
0
76
Dem Fehler auf der Spur - Mobile Testing Days 2015
florianbuerger
0
78
WatchKit overview
florianbuerger
0
160
Swift Intro
florianbuerger
1
210
Debugging & Profiling
florianbuerger
1
49
AppCode versus Xcode
florianbuerger
0
440
Other Decks in Programming
See All in Programming
Agent Skills Workshop - AIへの頼み方を仕組み化する
gotalab555
15
8.3k
Claude Codeセッション現状確認 2026福岡 / fukuoka-aicoding-00-beacon
monochromegane
4
410
2026年は Rust 置き換えが流行る! / 20260220-niigata-5min-tech
girigiribauer
0
230
RAGでハマりがちな"Excelの罠"を、データの構造化で突破する
harumiweb
9
2.7k
AIに任せる範囲を安全に広げるためにやっていること
fukucheee
0
130
AI時代でも変わらない技術コミュニティの力~10年続く“ゆるい”つながりが生み出す価値
n_takehata
2
690
Windows on Ryzen and I
seosoft
0
230
モジュラモノリスにおける境界をGoのinternalパッケージで守る
magavel
0
3.5k
nuget-server - あなたが必要だったNuGetサーバー
kekyo
PRO
0
220
エンジニアの「手元の自動化」を加速するn8n 2026.02.27
symy2co
0
130
maplibre-gl-layers - 地図に移動体たくさん表示したい
kekyo
PRO
0
230
New in Go 1.26 Implementing go fix in product development
sunecosuri
0
400
Featured
See All Featured
BBQ
matthewcrist
89
10k
Building AI with AI
inesmontani
PRO
1
780
How STYLIGHT went responsive
nonsquared
100
6k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
54k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
460
Optimising Largest Contentful Paint
csswizardry
37
3.6k
A Soul's Torment
seathinner
5
2.4k
Claude Code どこまでも/ Claude Code Everywhere
nwiizo
64
53k
My Coaching Mixtape
mlcsv
0
69
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.8k
AI: The stuff that nobody shows you
jnunemaker
PRO
3
360
How to Grow Your eCommerce with AI & Automation
katarinadahlin
PRO
1
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?