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
62
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
64
Dem Fehler auf der Spur - Mobile Testing Days 2015
florianbuerger
0
64
WatchKit overview
florianbuerger
0
110
Swift Intro
florianbuerger
1
160
Debugging & Profiling
florianbuerger
1
43
AppCode versus Xcode
florianbuerger
0
380
Other Decks in Programming
See All in Programming
SymfonyCon Vienna 2025: Twig, still relevant in 2025?
fabpot
3
1.2k
フロントエンドのディレクトリ構成どうしてる? Feature-Sliced Design 導入体験談
osakatechlab
8
4.1k
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
750
良いユニットテストを書こう
mototakatsu
7
2.1k
MCP with Cloudflare Workers
yusukebe
2
220
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
Jakarta EE meets AI
ivargrimstad
0
240
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
PSR-15 はあなたのための ものではない? - phpcon2024
myamagishi
0
110
競技プログラミングへのお誘い@阪大BOOSTセミナー
kotamanegi
0
360
Scalaから始めるOpenFeature入門 / Scalaわいわい勉強会 #4
arthur1
1
320
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
Featured
See All Featured
Building an army of robots
kneath
302
44k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Unsuck your backbone
ammeep
669
57k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.2k
Speed Design
sergeychernyshev
25
670
Making Projects Easy
brettharned
116
5.9k
The Power of CSS Pseudo Elements
geoffreycrofte
73
5.4k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
38
1.9k
A Modern Web Designer's Workflow
chriscoyier
693
190k
YesSQL, Process and Tooling at Scale
rocio
169
14k
RailsConf 2023
tenderlove
29
940
No one is an island. Learnings from fostering a developers community.
thoeni
19
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?