Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Protocols and The Promised Land Take 2
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
Michele
March 02, 2016
Programming
76
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Protocols and The Promised Land Take 2
try! Swift edition
Michele
March 02, 2016
More Decks by Michele
See All by Michele
Protocols and the Promised Land
mtitolo
1
15k
Other Decks in Programming
See All in Programming
フロントエンドUIフレームワークのこれまでとこれから
ssssota
5
2.9k
The Good Stuff, Not the Slop: Engineering High-Quality Android Apps with Modern AI Tooling
danybony
1
260
MVNOの申込からeSIM開通までをiOSアプリでつなぐ- 本人確認・MNP・通信事業者基盤をまたぐ実装
satotakeshi
0
460
そのリトライ、死んだコネクションを使い回していませんか ── GoのHTTPクライアントとHTTP/2を実プロダクト障害から学び直す
myus4a
0
220
手動確認はもう限界 〜XCUITestでCustom URL Schemeの遷移を起動種別ごとに自動テストする〜 / Testing Custom URL Schemes with XCUITest
otouto
0
330
LoopHub - ローカルで動く GitHub で、AI と共同開発
jugyo
1
570
マイコン向けの軽量Ruby「PicoRuby」で各種デバイスを制御するネイティブアプリの実現手法
bash0c7
0
440
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2.3k
Verilogで学ぶCPU自作入門.pdf
uyuki234
2
1.7k
Omarchy Tokyo やると聞いて UMPC 買ってセットアップしてきた
mtsmfm
0
160
AI が書く Go コードの品質を劇的に向上させる Linter: “declscope”
mpyw
0
380
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
130
Featured
See All Featured
How to Get Subject Matter Experts Bought In and Actively Contributing to SEO & PR Initiatives.
livdayseo
0
200
XXLCSS - How to scale CSS and keep your sanity
sugarenia
250
1.3M
How GitHub (no longer) Works
holman
316
150k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
9.2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
28
3.6k
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
74
42k
sira's awesome portfolio website redesign presentation
elsirapls
0
420
Accessibility Awareness
sabderemane
1
220
Exploring anti-patterns in Rails
aemeredith
4
510
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
330
Chasing Engaging Ingredients in Design
codingconduct
0
320
Transcript
Protocols and the Promised Land @MicheleTitolo
Swift is shiny! And new!
Swift is not Objective-C
Interop
as? as? as?
as? lies
let vendor = ObjcObject() let items = vendor.giveMeItems() as? [Fruit]
let vendor = ObjcObject() let items = vendor.giveMeItems().map { $0
as Fruit }
@objc spreads like a virus
@objc protocol SomeProtocol { func someFunc() } class MyClass: SomeProtocol
{}
@objc protocol SomeProtocol { func someFunc() } @objc class MyClass:
NSObject, SomeProtocol {}
Swift > Objc > Swift
Can’t #import “MyApp-Swift.h” in header
Can’t conform, can’t subclass
Bridging
many parts of Swift don’t bridge
Does this really need to be used in Objective-C?
framework headers can’t be in bridging header
use @import
Partial bridging
-Swift.h will leave out funcs/vars that don’t bridge
Again: does this really need to be bridged?
Type System
properties can have 1 type
protocol Themeable {} class ListViewController: UIViewController, Themeable {} var themedViewController:
// UIViewController, Themeable ????
two workarounds
public protocol ViewControllerProtocol { var view: UIView! { get }
var storyboard: UIStoryboard? { get } init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) func viewDidLoad() // etc } protocol ThemeableViewController: Themeable, ViewControllerProtocol {} var themedViewController: ThemeableViewController Swift-y but hack-y
var themed: Themeable { get { return self.viewController as! Themeable
} set(newThemeable) { if let themedViewController = newThemeable as? UIViewController{ viewController = themedViewController } } } var viewController: UIViewController init<T where T: Themeable, T: UIViewController>(viewController: T) { self.viewController = viewController } Also swfit-y also hack-y
Can’t override type with inheritance
Deep object hierarchies
Protocols
Composition instead of inheritance
Protocols and inheritance don’t mix
use POP to mock
Generics
Can’t reference a generic protocol
protocol Holder { typealias Item var items: [Item] { get
} } class Basket<Thing>: Holder{ var items: [Thing] = [] func add(item: Thing) { items.append(item) } }
var someHolder: Holder var someBasket: Basket
var someHolder: Holder<Peach> var someBasket: Basket<Peach>
Covariance only works with generic classes
Covariance: If a Cat is an Animal func feed(animal: Animal)
can receive a Cat
typealias Object typealias Object: String typealias RoundObject: Object
generic classes can specify type requirements
class Basket<Thing: Fruit> { var items: [Thing] = [] func
add(item: Thing) { items.append(item) } }
class Basket<Thing: Fruit> { var items: [Thing] = [] func
add(item: Thing) { items.append(item) } } class FruitBasket: Basket<Fruit> {} class PeachBasket: FruitBasket<Peach> {}
class Bag<Stuff> { class Basket<Thing: Stuff> { var items: [Thing]
= [] func add(item: Thing) { items.append(item) } } }
Generic non-NSObjects have issues
Explicitly call out class for now
Swift introduces awesome new patterns
Thanks! @MicheleTitolo
Photo Credits • https://www.flickr.com/photos/83073191@N00/21709516808/ • https://www.flickr.com/photos/64181484@N04/21946459678/ • https://www.flickr.com/photos/66904032@N05/18905223864/ • https://www.flickr.com/photos/27454212@N00/22120629112/
• https://www.flickr.com/photos/8725928@N02/24439195435/ • https://www.flickr.com/photos/28480761@N04/24143685631/