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
Swizzling NSObject classes in Swift
Search
codelynx
March 16, 2021
200
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Swizzling NSObject classes in Swift
codelynx
March 16, 2021
More Decks by codelynx
See All by codelynx
AI & Enginnering
codelynx
0
220
Claude codeで 創る世界と壊れる世界
codelynx
0
250
Caude codeで爆速開発
codelynx
0
210
2024-05-yumemi.pdf
codelynx
0
420
ユーザーたった一人のアプリ開発記
codelynx
0
390
Hello New Project
codelynx
1
330
WWDC21/Xcode13
codelynx
0
290
Tailor_your_Metal_apps_for_Apple_M1.pdf
codelynx
0
160
Delegate Chaining Workaround
codelynx
0
85
Featured
See All Featured
Darren the Foodie - Storyboard
khoart
PRO
4
3.9k
The Curious Case for Waylosing
cassininazir
1
540
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
Unlocking the hidden potential of vector embeddings in international SEO
frankvandijk
0
950
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.5k
We Have a Design System, Now What?
morganepeng
55
8.3k
Mobile First: as difficult as doing things right
swwweet
225
10k
Context Engineering - Making Every Token Count
addyosmani
9
1.2k
Measuring & Analyzing Core Web Vitals
bluesmoon
9
1k
Design of three-dimensional binary manipulators for pick-and-place task avoiding obstacles (IECON2024)
konakalab
0
600
A Modern Web Designer's Workflow
chriscoyier
699
190k
How to audit for AI Accessibility on your Front & Back End
davetheseo
0
550
Transcript
Swizzing NSObject classes Kaz Yoshikawa FEB 2021
Swizzling • To be able to replace or to override
existing NSObject methods • UIViewController viewDidAppear UIViewController myViewDidAppear viewDidAppear Before After viewDidAppear viewDidAppear
What’s for? • Analytics for user tracking • eg. Logging
extra information of all viewDidAppear methods • Application wide behavior changes • Tap on UIButton to speech before sendAction() get invoked
Example func swizzleMethod(_ `class`: AnyClass, _ original: Selector, _ swizzled:
Selector) { if let original = class_getInstanceMethod(`class`, original), let swizzled = class_getInstanceMethod(`class`, swizzled) { method_exchangeImplementations(original, swizzled) } else { print("failed to swizzle: \(`class`.self), '\(original)', '\(swizzled)'") } } swizzleMethod( UIViewController.self, #selector(UIViewController.viewDidAppear(_:)), #selector(UIViewController.viewDidAppear_x(_:)) ) public extension UIViewController { @objc private func viewWillAppear_x(_ animated: Bool) { print(Self.self, #function) self.viewWillAppear_x(animated) } }
Consideration • Do not abuse • Apple may terminate or
discontinue this mechanism in the future
Code • https://gist.github.com/codelynx/3685e0530607746a0811dfd3d1fe ff 9e
Thank you