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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
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
GraphQL の onError と Nullability のこれから
quramy
0
200
Railsバージョンを4倍にした話
optim
0
920
作れる、でも消せるか?──安全に「枯らして消す」機能削除術 / Drain, Then Delete
chobishiba
3
1.4k
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
340
graphql-ruby を Spinel で速くしようとした話
mtsmfm
0
140
SFCで実現する病院・医療システムの動的組み立て式UI
koukimiura
1
170
3回つくってわかった、 定期実行ジョブ基盤の本質情報
takai
4
3.7k
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
720
[DroidKnights 2026] Workflow AX: From Auto-Documented Policies to E2E Testing
raeminkang
0
520
Vapor Mode でアクセシビリティは 壊れないか検証した話
fuqda
1
320
React Native経験者が Flutterを30⽇間触って驚いたこと
3saito
0
150
ChromeでローカルLLM
ryu1013
0
190
Featured
See All Featured
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
480
Building the Perfect Custom Keyboard
takai
2
950
How GitHub (no longer) Works
holman
316
150k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
650
Odyssey Design
rkendrick25
PRO
2
920
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
580
Code Reviewing Like a Champion
maltzj
529
40k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
What the history of the web can teach us about the future of AI
inesmontani
PRO
2
790
Making Projects Easy
brettharned
120
6.8k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
20k
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/