SlideShare a Scribd company logo
Disclaimer
This talk is mostly for educational purposes.
⚠
A bit on the Swift runtime.
It’s turtles, all the way down.
• Apple platforms utilise the Objective-C runtime, Swift runs on top of this (iOS 7,
macOS 10.11+).

• Linux (and other platforms) don’t use this runtime. They ship with a “corelibs”
library that creates a runtime for Swift, but it is much smaller and doesn’t
support Objective-C.

• So only on Apple platforms can you inter-op Swift & Objective-C.

• But that also means Swift also has access to the same runtime environment as
Objective-C! (Through ObjectiveC - A swift library present on Apple systems).

• Yay! (uh-oh)
OOP
We made Alan Kay very sad (Please watch! https://www.youtube.com/watch?v=NdSD07U5uBs)
• OOP was originally designed to mimic natural biological systems.

• You have an object and it has properties. How do you find those properties?
You talk to the object. And if it understands you, it will respond.

• Objective-C is closer to the original design of OOP when compared to Java, C+
+, Pure Swift.

• objc_msgSend(id, SEL, …args) -> id* is truly dynamic.
• * This is no longer the signature due to ABI, but it sort of is as it’s
implemented in assembly. -> https://www.mikeash.com/pyblog/
objc_msgsends-new-prototype.html
Method Swizzling with Objective-C
A Smalltalk object can do exactly three things: 

• Hold state (references to other objects).

• Receive a message from itself or another object.

• In the course of processing a message, send messages to itself or another object.

The state an object holds is always private to that object. Other objects can query or
change that state only by sending requests (messages) to the object to do so. Any
message can be sent to any object: when a message is received, the receiver determines
whether that message is appropriate. Alan Kay has commented that despite the attention
given to objects, messaging is the most important concept in Smalltalk: "The big idea is
'messaging'—that is what the kernel of Smalltalk/Squeak is all about
Objectively speaking
Cells vs Gears
Fluidity vs Rigidity
Method Swizzling with Objective-C
Method Swizzling with Objective-C
objc_msgSend(id, SEL, …args)
A thingy A message It’s caveats
objc_msgSend(self, viewDidAppear, [animated:true]);
Hello Mr.ViewController. Could you appear please? And when you do, could you
animate?
Monkey Patching
🐒
• The Objective-C runtime allows you to rebind the way an object will respond
to messages.

• This is known as Swizzling.

• Apparently no one remembers where that name came from.
I’m going to say uh-oh again.
The possibilities are frightening.
• ViewControllers that actually call viewDidDisappear when you call viewDidAppear.

• Additions turning to subtraction.

• All of your data getting slurped up on applicationDidLaunch…Hello Google and Facebook
SDKs!

• Facebook Swizzles didMoveToWindow, setDelegate.

• https://github.com/facebook/facebook-ios-sdk/search?
q=FBSDKSwizzler&type=code

• Google Swizzles viewDidAppear, viewDidDisappear:

• https://github.com/firebase/firebase-ios-sdk/search?q=swizzleClass
AOP
No, not Air Observation Post. Aspect orientated programming!
• Non business logic (non functional requirements) are concerns that need “weaved” into your application.

• Common use cases; Logging, Security, Profiling, Transaction Management, Analytics.

• Really useful for adding an “aspect” of functionality to your app. i.e your app doesn’t have logging at the
moment, but you’ve got 600 screens and you want to add it to all of them.

• Solves a few problems;

• Reduces boilerplate.

• Keeps unrelated code separated from business logic.

• Dynamic application of function. Turn aspect on/off based on flags.

• Allows you to open closed interfaces (uh-oh x3).
Method Swizzling with Objective-C
Demo
Further reading
An evolutionary dead end, but an interesting one all the same.
• Anything by Alan Kay or Joe Armstrong on OOP

• https://medium.com/chmcore/a-short-history-of-objective-c-aff9d2bde8dd

• Akka Actors show how message passing works even in a networked system.

• https://doc.akka.io/docs/akka/current/typed/actors.html#akka-actors

• https://www.mikeash.com/pyblog/objc_msgsends-new-prototype.html

• https://indiestack.com/2019/10/casting-objective-c-message-sends/

More Related Content

What's hot (20)

PDF
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Raunak Talwar
 
PPT
Java EE revisits design patterns
Alex Theedom
 
PDF
iOS Memory management & Navigation
Marian Ignev
 
PDF
Promoter – A Python Project for Replicating a JSS via the API
macbrained
 
PDF
Actor model : A Different Concurrency Approach
Emre Akış
 
PPTX
Make Mobile Apps Quickly
Gil Irizarry
 
PDF
Contributing to the Community
WO Community
 
PPTX
The Actor Model - Towards Better Concurrency
Dror Bereznitsky
 
PPTX
Search and analyze your data with elasticsearch
Anton Udovychenko
 
PDF
Building applications with akka.net
Anthony Brown
 
PDF
Building a Lightweight Discovery Interface for China's Patents@NYC Solr/Lucen...
OpenSource Connections
 
PDF
Actor model in .NET - Akka.NET
Konrad Dusza
 
PPTX
"Walk in a distributed systems park with Orleans" Евгений Бобров
Fwdays
 
PPTX
Creating scalable message driven solutions akkadotnet
David Hoerster
 
PPTX
Massively Scaleable .NET Web Services with Project Orleans
Newman Hunter
 
PPTX
CQRS + ES with Scala and Akka
Bharadwaj N
 
PDF
Memory Management in RubyMotion
Michael Denomy
 
PDF
Actor Patterns and NATS - Boulder Meetup
Apcera
 
PDF
A gentle introduction into AKKA and the actor model
Mykhailo Kotsur
 
PPTX
Akka Fundamentals
Michael Kendra
 
Avoid memory leaks using unit tests - Swift Delhi Meetup - Chapter 15
Raunak Talwar
 
Java EE revisits design patterns
Alex Theedom
 
iOS Memory management & Navigation
Marian Ignev
 
Promoter – A Python Project for Replicating a JSS via the API
macbrained
 
Actor model : A Different Concurrency Approach
Emre Akış
 
Make Mobile Apps Quickly
Gil Irizarry
 
Contributing to the Community
WO Community
 
The Actor Model - Towards Better Concurrency
Dror Bereznitsky
 
Search and analyze your data with elasticsearch
Anton Udovychenko
 
Building applications with akka.net
Anthony Brown
 
Building a Lightweight Discovery Interface for China's Patents@NYC Solr/Lucen...
OpenSource Connections
 
Actor model in .NET - Akka.NET
Konrad Dusza
 
"Walk in a distributed systems park with Orleans" Евгений Бобров
Fwdays
 
Creating scalable message driven solutions akkadotnet
David Hoerster
 
Massively Scaleable .NET Web Services with Project Orleans
Newman Hunter
 
CQRS + ES with Scala and Akka
Bharadwaj N
 
Memory Management in RubyMotion
Michael Denomy
 
Actor Patterns and NATS - Boulder Meetup
Apcera
 
A gentle introduction into AKKA and the actor model
Mykhailo Kotsur
 
Akka Fundamentals
Michael Kendra
 

Similar to Method Swizzling with Objective-C (20)

PDF
Никита Корчагин - Programming Apple iOS with Objective-C
DataArt
 
PDF
What Makes Objective C Dynamic?
Kyle Oba
 
PPTX
Intro to iOS: Object Oriented Programming and Objective-C
Andrew Rohn
 
PPT
iOS Application Development
Compare Infobase Limited
 
PDF
Objective-C
Abdlhadi Oul
 
PPT
Ios development
Shakil Ahmed
 
PDF
Objc
Pragati Singh
 
PDF
Programming with Objective-C
Nagendra Ram
 
PDF
Bootstrapping iPhone Development
ThoughtWorks
 
PDF
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
PDF
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
lindzpeccoo
 
PPTX
Introduction to Objective - C
Asim Rais Siddiqui
 
PDF
Objective-C Is Not Java
Chris Adamson
 
PDF
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
PPT
Objective-C for iOS Application Development
Dhaval Kaneria
 
PDF
Objective-C talk
bradringel
 
PPTX
iOS development introduction
paramisoft
 
PPTX
Swift programming language
Nijo Job
 
PPTX
iOS,From Development to Distribution
Tunvir Rahman Tusher
 
PDF
Intro to Objective C
Ashiq Uz Zoha
 
Никита Корчагин - Programming Apple iOS with Objective-C
DataArt
 
What Makes Objective C Dynamic?
Kyle Oba
 
Intro to iOS: Object Oriented Programming and Objective-C
Andrew Rohn
 
iOS Application Development
Compare Infobase Limited
 
Objective-C
Abdlhadi Oul
 
Ios development
Shakil Ahmed
 
Programming with Objective-C
Nagendra Ram
 
Bootstrapping iPhone Development
ThoughtWorks
 
Programming iOS 4 Fundamentals of iPhone iPad and iPod Touch Development 1st ...
assangkaoua
 
Programming Ios 5 2nd Edition 2nd Early Release Draft Matt Neuburg
lindzpeccoo
 
Introduction to Objective - C
Asim Rais Siddiqui
 
Objective-C Is Not Java
Chris Adamson
 
Programming Ios 4 Fundamentals Of Iphone Ipad And Ipod Touch Development 1st ...
jungieaugi
 
Objective-C for iOS Application Development
Dhaval Kaneria
 
Objective-C talk
bradringel
 
iOS development introduction
paramisoft
 
Swift programming language
Nijo Job
 
iOS,From Development to Distribution
Tunvir Rahman Tusher
 
Intro to Objective C
Ashiq Uz Zoha
 
Ad

Recently uploaded (20)

PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PPTX
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
PDF
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
PDF
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PDF
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPTX
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
From Sci-Fi to Reality: Exploring AI Evolution
Svetlana Meissner
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Kit-Works Team Study_20250627_한달만에만든사내서비스키링(양다윗).pdf
Wonjun Hwang
 
The 2025 InfraRed Report - Redpoint Ventures
Razin Mustafiz
 
The Rise of AI and IoT in Mobile App Tech.pdf
IMG Global Infotech
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
“NPU IP Hardware Shaped Through Software and Use-case Analysis,” a Presentati...
Edge AI and Vision Alliance
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
What’s my job again? Slides from Mark Simos talk at 2025 Tampa BSides
Mark Simos
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
AI Penetration Testing Essentials: A Cybersecurity Guide for 2025
defencerabbit Team
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
CIFDAQ Market Wrap for the week of 4th July 2025
CIFDAQ
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Ad

Method Swizzling with Objective-C

  • 1. Disclaimer This talk is mostly for educational purposes. ⚠
  • 2. A bit on the Swift runtime. It’s turtles, all the way down. • Apple platforms utilise the Objective-C runtime, Swift runs on top of this (iOS 7, macOS 10.11+). • Linux (and other platforms) don’t use this runtime. They ship with a “corelibs” library that creates a runtime for Swift, but it is much smaller and doesn’t support Objective-C. • So only on Apple platforms can you inter-op Swift & Objective-C. • But that also means Swift also has access to the same runtime environment as Objective-C! (Through ObjectiveC - A swift library present on Apple systems). • Yay! (uh-oh)
  • 3. OOP We made Alan Kay very sad (Please watch! https://www.youtube.com/watch?v=NdSD07U5uBs) • OOP was originally designed to mimic natural biological systems. • You have an object and it has properties. How do you find those properties? You talk to the object. And if it understands you, it will respond. • Objective-C is closer to the original design of OOP when compared to Java, C+ +, Pure Swift. • objc_msgSend(id, SEL, …args) -> id* is truly dynamic. • * This is no longer the signature due to ABI, but it sort of is as it’s implemented in assembly. -> https://www.mikeash.com/pyblog/ objc_msgsends-new-prototype.html
  • 5. A Smalltalk object can do exactly three things: • Hold state (references to other objects). • Receive a message from itself or another object. • In the course of processing a message, send messages to itself or another object. The state an object holds is always private to that object. Other objects can query or change that state only by sending requests (messages) to the object to do so. Any message can be sent to any object: when a message is received, the receiver determines whether that message is appropriate. Alan Kay has commented that despite the attention given to objects, messaging is the most important concept in Smalltalk: "The big idea is 'messaging'—that is what the kernel of Smalltalk/Squeak is all about Objectively speaking
  • 9. objc_msgSend(id, SEL, …args) A thingy A message It’s caveats objc_msgSend(self, viewDidAppear, [animated:true]); Hello Mr.ViewController. Could you appear please? And when you do, could you animate?
  • 10. Monkey Patching 🐒 • The Objective-C runtime allows you to rebind the way an object will respond to messages. • This is known as Swizzling. • Apparently no one remembers where that name came from.
  • 11. I’m going to say uh-oh again. The possibilities are frightening. • ViewControllers that actually call viewDidDisappear when you call viewDidAppear. • Additions turning to subtraction. • All of your data getting slurped up on applicationDidLaunch…Hello Google and Facebook SDKs! • Facebook Swizzles didMoveToWindow, setDelegate. • https://github.com/facebook/facebook-ios-sdk/search? q=FBSDKSwizzler&type=code • Google Swizzles viewDidAppear, viewDidDisappear: • https://github.com/firebase/firebase-ios-sdk/search?q=swizzleClass
  • 12. AOP No, not Air Observation Post. Aspect orientated programming! • Non business logic (non functional requirements) are concerns that need “weaved” into your application. • Common use cases; Logging, Security, Profiling, Transaction Management, Analytics. • Really useful for adding an “aspect” of functionality to your app. i.e your app doesn’t have logging at the moment, but you’ve got 600 screens and you want to add it to all of them. • Solves a few problems; • Reduces boilerplate. • Keeps unrelated code separated from business logic. • Dynamic application of function. Turn aspect on/off based on flags. • Allows you to open closed interfaces (uh-oh x3).
  • 14. Demo
  • 15. Further reading An evolutionary dead end, but an interesting one all the same. • Anything by Alan Kay or Joe Armstrong on OOP • https://medium.com/chmcore/a-short-history-of-objective-c-aff9d2bde8dd • Akka Actors show how message passing works even in a networked system. • https://doc.akka.io/docs/akka/current/typed/actors.html#akka-actors • https://www.mikeash.com/pyblog/objc_msgsends-new-prototype.html • https://indiestack.com/2019/10/casting-objective-c-message-sends/