SlideShare a Scribd company logo
Dynamic Swift
Saul Mora
@casademora
saul.mora@liulishuo.com
•dynamic
•@objc
•NSObject
Objective C Runtime
-(BOOL) resolveInstanceMethod:(SEL)aSelector
-(id) forwardingTargetForSelector:(SEL)aSelector
-(NSMethodSignature *) methodSignatureForSelector:(SEL)aSelector
-(void) forwardInvocation:(NSInvocation *)anInvocation
Target/Action
Method Swizzling
Responder Chain
Responder Chain
"I want something that works like
the responder chain…"
let first = FirstHandlerType()
let second = SecondHandlerType(next: first)
let third = ThirdHandlerType(next: second)
class Operation: NSObject
{
let nextOperation: Operation?
init(next: Operation? = nil)
{
self.nextOperation = next
}
override func forwardingTarget(for aSelector: Selector!) -> Any?
{
print(String(describing: self))
return nextOperation
}
}
third.doSomething()
Playground execution failed: error: Dynamic Swift.playground:35:1: error:
value of type 'ThirdHandlerType' has no member 'doSomething'
third.doSomething()
^~~~~ ~~~~~~~~~~~
* thread #1: tid = 0x61b09, 0x000000010f3713c0 Dynamic
Swift`executePlayground, queue = 'com.apple.main-thread', stop reason =
breakpoint 1.2
* frame #0: 0x000000010f3713c0 Dynamic Swift`executePlayground
frame #1: 0x000000010f3709c0 Dynamic Swift`__37-[XCPAppDelegate
enqueueRunLoopBlock]_block_invoke + 32
frame #2: 0x000000010fe8c6ac
CoreFoundation`__CFRUNLOOP_IS_CALLING_OUT_TO_A_BLOCK__ + 12
frame #3: 0x000000010fe716f4 CoreFoundation`__CFRunLoopDoBlocks + 356
frame #4: 0x000000010fe70e65 CoreFoundation`__CFRunLoopRun + 901
frame #5: 0x000000010fe70884 CoreFoundation`CFRunLoopRunSpecific + 420
frame #6: 0x000000011539ba6f GraphicsServices`GSEventRunModal + 161
frame #7: 0x0000000111b07c68 UIKit`UIApplicationMain + 159
frame #8: 0x000000010f3706e9 Dynamic Swift`main + 201
frame #9: 0x00000001134e568d libdyld.dylib`start + 1
frame #10: 0x00000001134e568d libdyld.dylib`start + 1
FAIL
One Weird Trick…!
let third: AnyObject = ThirdHandlerType(next: second)
<__lldb_expr_86.ThirdHandlerType:
0x608000034f60>
<__lldb_expr_86.SecondHandlerType:
0x608000034ec0>
Did: <__lldb_expr_86.FirstHandlerType:
0x600000033080>
http://tinyurl.com/
dynamicswiftdemo
Dynamic Swift
Saul Mora
@casademora
saul.mora@liulishuo.com

More Related Content

PPT
Constructor and Destructor PPT
PPT
Review constdestr
PPTX
Constructor and destructor
PPTX
C++ Constructor destructor
PPTX
Constructor and Types of Constructors
PPSX
Constructor and destructor
PPTX
Constructors and destructors
Constructor and Destructor PPT
Review constdestr
Constructor and destructor
C++ Constructor destructor
Constructor and Types of Constructors
Constructor and destructor
Constructors and destructors

What's hot (20)

PDF
Constructors and Destructors
PPT
Constructor & Destructor
PPT
Oop lec 5-(class objects, constructor & destructor)
PDF
Meta-objective Lisp @名古屋 Reject 会議
PPTX
constructor and destructor
PPTX
Constructor ppt
PPTX
constructors in java ppt
PDF
Constructor and Destructor
PPT
Nested loops
PDF
Pavel kravchenko obj c runtime
PPTX
Constructors and Destructors
PPTX
constructor & destructor in cpp
PPTX
Constructor and desturctor
PDF
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
PPT
Constructor
PPTX
Java8 and Functional Programming
PDF
Fluent14
PDF
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
PDF
Optionals by Matt Faluotico
PPTX
Constructor and Destructor in c++
Constructors and Destructors
Constructor & Destructor
Oop lec 5-(class objects, constructor & destructor)
Meta-objective Lisp @名古屋 Reject 会議
constructor and destructor
Constructor ppt
constructors in java ppt
Constructor and Destructor
Nested loops
Pavel kravchenko obj c runtime
Constructors and Destructors
constructor & destructor in cpp
Constructor and desturctor
Value Objects, Full Throttle (to be updated for spring TC39 meetings)
Constructor
Java8 and Functional Programming
Fluent14
Kotlin - The Swiss army knife of programming languages - Visma Mobile Meet-up...
Optionals by Matt Faluotico
Constructor and Destructor in c++
Ad

Similar to Dynamic Swift (20)

KEY
RubyistのためのObjective-C入門
PPTX
Ios development
PDF
Swift rocks! #1
PDF
Swift Ready for Production?
PDF
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
PDF
The Ring programming language version 1.5.2 book - Part 37 of 181
PDF
iOS NSAgora #3: Objective-C vs. Swift
PPTX
iOS Session-2
PDF
Manual specialization
PDF
Denis Lebedev, Swift
KEY
Objective-C Survives
PDF
Денис Лебедев, Swift
PDF
Live Updating Swift Code
PDF
Spock: Test Well and Prosper
KEY
DjangoCon US 2011 - Monkeying around at New Relic
KEY
Djangocon11: Monkeying around at New Relic
PDF
Message in a bottle
PPTX
Interface result set
PDF
The Ring programming language version 1.5.1 book - Part 36 of 180
PPTX
SQLITE PARA UNA BUENA ADMINISTRACION DE DATOS EN LAS EMPRESAS
RubyistのためのObjective-C入門
Ios development
Swift rocks! #1
Swift Ready for Production?
«Objective-C Runtime в примерах» — Алексей Сторожев, e-Legion
The Ring programming language version 1.5.2 book - Part 37 of 181
iOS NSAgora #3: Objective-C vs. Swift
iOS Session-2
Manual specialization
Denis Lebedev, Swift
Objective-C Survives
Денис Лебедев, Swift
Live Updating Swift Code
Spock: Test Well and Prosper
DjangoCon US 2011 - Monkeying around at New Relic
Djangocon11: Monkeying around at New Relic
Message in a bottle
Interface result set
The Ring programming language version 1.5.1 book - Part 36 of 180
SQLITE PARA UNA BUENA ADMINISTRACION DE DATOS EN LAS EMPRESAS
Ad

Recently uploaded (20)

PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Essential Infomation Tech presentation.pptx
PDF
PTS Company Brochure 2025 (1).pdf.......
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
Transform Your Business with a Software ERP System
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PPTX
ai tools demonstartion for schools and inter college
PPTX
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Introduction to Artificial Intelligence
PDF
medical staffing services at VALiNTRY
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Essential Infomation Tech presentation.pptx
PTS Company Brochure 2025 (1).pdf.......
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Transform Your Business with a Software ERP System
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
Design an Analysis of Algorithms I-SECS-1021-03
Understanding Forklifts - TECH EHS Solution
Design an Analysis of Algorithms II-SECS-1021-03
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How Creative Agencies Leverage Project Management Software.pdf
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
How to Choose the Right IT Partner for Your Business in Malaysia
ai tools demonstartion for schools and inter college
Agentic AI : A Practical Guide. Undersating, Implementing and Scaling Autono...
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Introduction to Artificial Intelligence
medical staffing services at VALiNTRY

Dynamic Swift