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
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
62
AppCode versus Xcode
florianbuerger
0
460
Other Decks in Programming
See All in Programming
AIで効率化できた業務・日常
ochtum
0
100
Semantic Version 単位で戦略を柔軟に変えて、パッケージアップデートを自動化する
daitasu
0
160
「AIで開発し、AIを届ける」をEvalでつなぐ 〜AIネイティブに始めるプロダクト開発の実践〜 / Connecting "Develop with AI, deliver AI" with Eval
rkaga
4
3.8k
Claspは野良GASの夢をみるか
takter00
0
170
Old Dog, New Tricks: The Java 25 Reinvention - JNation
bazlur_rahman
0
150
Modding RubyKaigi for Myself
yui_knk
0
890
Javaの型とAI時代に型が大事な理由 / java types and type in AI era
kishida
2
110
AutonomyとControlのあいだ:Graflowで記述するAIエージェント協調
myui
0
110
net-httpのHTTP/2対応について
naruse
0
450
CLIであることを活かしたGitHub Copilot CLI活用術 / GitHub Copilot CLI Pro Tips & Tricks
nao_mk2
1
1.2k
生成AI時代にこそ効くGo | Why Go Works in the Age of Generative AI
mom0tomo
8
3.1k
ローカルLLMを使ってB2Bサービスを作っていての学び
yaotti
0
140
Featured
See All Featured
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
200
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
1.6k
Rebuilding a faster, lazier Slack
samanthasiow
85
9.5k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Side Projects
sachag
455
43k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.7k
The Curse of the Amulet
leimatthew05
1
13k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
The Curious Case for Waylosing
cassininazir
1
380
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
4k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
600
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?