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
63
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
70
Dem Fehler auf der Spur - Mobile Testing Days 2015
florianbuerger
0
67
WatchKit overview
florianbuerger
0
130
Swift Intro
florianbuerger
1
180
Debugging & Profiling
florianbuerger
1
46
AppCode versus Xcode
florianbuerger
0
400
Other Decks in Programming
See All in Programming
Serving TUIs over SSH with Go
caarlos0
0
750
Designing Your Organization's Test Pyramid ( #scrumniigata )
teyamagu
PRO
5
1.6k
エンジニアが挑む、限界までの越境
nealle
1
330
オープンソースコントリビュート入門
_katsuma
0
140
Instrumentsを使用した アプリのパフォーマンス向上方法
hinakko
0
250
VitestのIn-Source Testingが便利
taro28
9
2.5k
Flutterでllama.cppをつかってローカルLLMを試してみた
sakuraidayo
0
150
Beyond_the_Prompt__Evaluating__Testing__and_Securing_LLM_Applications.pdf
meteatamel
0
110
医療系ソフトウェアのAI駆動開発
koukimiura
1
140
カウシェで Four Keys の改善を試みた理由
ike002jp
1
140
知識0からカンファレンスやってみたらこうなった!
syossan27
5
280
2025年のz-index設計を考える
tak_dcxi
12
4.8k
Featured
See All Featured
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
251
21k
BBQ
matthewcrist
88
9.6k
Building Better People: How to give real-time feedback that sticks.
wjessup
368
19k
Designing for Performance
lara
608
69k
Building a Modern Day E-commerce SEO Strategy
aleyda
40
7.3k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
GraphQLの誤解/rethinking-graphql
sonatard
71
11k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
233
17k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
It's Worth the Effort
3n
184
28k
Navigating Team Friction
lara
185
15k
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?