SlideShare a Scribd company logo
The Dark Side
of Objective-C
Martin Kiss | kish | @Tricertops PixelCut s. r. o.
Objective-C Runtime

Creates illusion of objects and messages
@interface
@implementation
[self bracketSyntax]
@property (strong)
self.dotSyntax
@selector()
- (void)methodDeclarations:(id)weird
The Light Side
The Dark Side
objc_allocateClassPair()
class_copyMethodList()
objc_msgSend()
class_getProperty()
class_copyIvarList()
sel_registerName()
method_setImplementation()
What is Runtime?
• C support library

• Manages classes and methods

• Handles method invocations

• Memory management routines

• Manages lifetime of weak references
Why should Swift care?
• Swift is a new syntax for Objective-C

• Frameworks are all in Objective-C

• NSObject and @objc

• Many of things are not possible, yet

• Swift will need its own runtime
What needs runtime?
• NSCoding

• Storyboards & XIBs

• Key-Value Coding

• Key-Value Observing

• Core Animation

• Testing & Mocking
• Core Data

• NSProxy

• UIAppearance

• NSUndoManager

• Cocoa Bindings

• UIResponder
#import <objc/runtime.h>
#import <objc/message.h>
Simple Runtime
Services
Look up Class by Name
High Level
Low Level

How It Works

Used By
NSClassFromString()
objc_getClass()

objc_lookUpClass()
Runtime holds a table of all classes by
their names as keys

NSCoding, Storyboards, XIBs
Perform Selector by Name
High Level

Low Level

How It Works

Used By

NSSelectorFromString()

-performSelector:
sel_registerName()

objc_msgSend()
Classes store method implementations
in tables by selectors as keys

Key-Value Coding, Storyboards, XIBs,
UIControl, UIGestureRecognizer
Store Associated Objects
Functions

How It Works

What Is It For







Used By

objc_getAssociatedObject()

objc_setAssociatedObject()
Runtime holds side-table for each object
until it deallocates

Adding storage to objects without
adding ivars, for example rarely used
values

UIViews, Auto Layout, UIAppearance,
many more
Advanced Runtime
Services
Access Ivars by Name
Functions

How It Works



Used By
class_getInstanceVariable()

class_setInstanceVariable()
Instance variables are accessed
indirectly and classes contain lookup
table

Key-Value Coding, Key-Value Observing
Access Attributes of Properties
Functions

How It Works

What Is It For





Used By
class_getProperty()

property_getAttributes()
Classes include all info about properties,
like name, attributes, and backing ivar

Check if property is weak or strong or if
the property has ivar

Custom CALayer animatable properties
Enumerate Ivars & Properties
Functions

How It Works

What Is It For



Used By

class_copyIvarList()

class_copyPropertyList()
Classes include tables and metadata for
ivars and properties

Inspection of object contents

CALayer animatable properties, Core
Image Filters, automatic descriptions
Enumerate Methods
Function
How It Works

What Is It For



Used By
class_copyMethodList()
Classes include table of methods with
their selectors and implementations

Find methods that match a pattern

Tests & Mocks, UIAppearance
Enumerate Classes
Functions

How It Works

What Is It For

objc_copyClassList()

objc_copyClassNamesForImage()
Runtime holds table of all classes
loaded in your process, per executable

Find classes that match a pattern, find
all subclasses of a class
⚠
Warning: Accessing framework classes will trigger side effects!
Sending Messages
Function
Related

How It Works

What Is It For

objc_msgSend()
-methodForSelector:

-methodSignatureForSelector:
All [bracket calls] are translated to
objc_msgSend()

Perform selectors when standard method

-performSelector: is not enough
⚠
Warning: Requires casting to work properly!
Sending Messages

How it works?
- (void)updateTitle:(NSString *)title {
title = title.trimmedString;

self.title = title;

self.navigationBar.title = title;

}
Sending Messages

Components of a method
updateTitle: void, id, SEL, NSString *
{
title = title.trimmedString;

self.title = title;

self.navigationBar.title = title;

}
Selector Type Signature
Implementation
Sending Messages

Components of a method
updateTitle: void, id, SEL, id
void func(id self, SEL _cmd, id title) {
title = title.trimmedString;

self.title = title;

self.navigationBar.title = title;

}
SEL
IMP
"v@:@"
Sending Messages
[object updateTitle:@"Hello"];
let message = void(*)(id,SEL,id)&objc_msgSend;
SEL selector = @selector(updateTitle:);
message(object, selector, @"Hello");
=
Expert Runtime
Services
learn t|he powER
of t|he dark Side!
Runtime is mutable
Add Methods to Classes
Function
Override

What Is It For

Used By

class_addMethod()
+resolveInstanceMethod:

+resolveClassMethod:
Implement methods on demand, for
example getters of @dynamic properties

Core Data, CALayer animatable
properties, UIAppearance, KVO
Replace Implementations
Functions



Override
What Is It For

Used By

class_replaceMethod()

method_setImplementation()

method_exchangeImplementations()
+load in categories

Extend existing framework classes with

new behaviors

UIAppearance, Key-Value Observing,

Mocking frameworks
⚠
Warning: It is not trivial to implement method swizzling properly!
Forward Invocations
Override



How It Works

What Is It For



Used By
-forwardInvocation:
Unrecognized selectors are passed into
this method before they throw exception

Simulate multiple inheritance, forward
methods to internal components, modify
arguments

NSProxy subclasses, NSUndoManager
Change Class of Object
Functions



How It Works

What Is It For

Used By
object_setClass()
Object has ivar isa, which points to the
class and is used for method lookup

Extend behavior of a single object, not
all objects of that class

Key-Value Observing, Core Data
⚠
Warning: New class should handle all methods of original class!
Create New Classes
Functions





How It Works

What Is It For

Used By
objc_allocateClassPair()

objc_registerClassPair()
Allocate, add methods, ivars, properties,
and then register in runtime

Customize class methods or for using
with object_setClass()

Key-Value Observing, Core Data
self
MyClass
lookup
message
What is Metaclass?

Implementations are looked up in class
Instance Methods
self
MyClass
MyMetaClass
lookup
lookup
message
message
Instance Methods
Class Methods
What is Metaclass?

Class is also an object, so it has a class
self
MyClass
MyMetaClass
lookup
lookup
message
message
Instance Methods
Class Methods
NSObject
message
lookup
How much is it used?

Measured using symbolic breakpoints
Minimal Swift App
import UIKit~~~~~~~~~~~~~~~
@UIApplicationMain~~~~~~~~~~~~~~~

class AppDelegate: NSObject,~~~~~~~~~~~~~~~

UIApplicationDelegate {}
• Initializes UIApplication & Main Run Loop

• No launch Storyboard or XIB
Minimal Swift App
Look up Class 608×
Look up Selector 718×
Get / Set Associated Object 254× / 179×
Copy Method List 378×
Add / Change Method 13× / 1×
Create Class 13×
iOS Dash App
• Documentation viewer

• Standard UI components

• UIKit & WebKit

• 20k LOC of Objective-C
iOS Dash App
Look up Class 1357×
Look up Selector 1283×
Get / Set Associated Object 2803× / 1317×
Copy Method List 515×
Add / Change Method 87× / 14×
Create Class 18×
iOS Kickstarter App
• Crowdfunding app

• Customized UI

• 120k LOC of mixed code
iOS Kickstarter App
Look up Class 2813×
Look up Selector 1455×
Get / Set Associated Object 4375× / 1966×
Copy Method List 496×
Add / Change Method 190× / 10×
Create Class 20×
PaintCode
• Vector drawing Mac app

• Custom complex UI

• 300k LOC of Objective-C

• XIBs with Cocoa Bindings
PaintCode
Look up Class 41189×
Look up Selector 9615×
Get / Set Associated Object 45230× / 2045×
Copy Method List 370×
Add / Change Method 664× / 1×
Create Class 112×
Ask me anything
Thank You
Martin Kiss | kish | @Tricertops PixelCut s. r. o.

More Related Content

What's hot

Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Sagar Verma
 
Unit ii
Unit iiUnit ii
Unit ii
snehaarao19
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
OUM SAOKOSAL
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
Sagar Verma
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
Ramrao Desai
 
Java 102 intro to object-oriented programming in java - exercises
Java 102   intro to object-oriented programming in java - exercisesJava 102   intro to object-oriented programming in java - exercises
Java 102 intro to object-oriented programming in java - exercises
agorolabs
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Sagar Verma
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
Partnered Health
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
Ram132
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Sagar Verma
 
Core java
Core javaCore java
Core java
kasaragaddaslide
 
Core java
Core java Core java
Core java
Ravi varma
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
Miles Sabin
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
Lorna Mitchell
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Sagar Verma
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
Muhammad Younis
 

What's hot (20)

Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
 
Unit ii
Unit iiUnit ii
Unit ii
 
Java OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - InheritanceJava OOP Programming language (Part 5) - Inheritance
Java OOP Programming language (Part 5) - Inheritance
 
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
OOPS in java | Super and this Keyword | Memory Management in java | pacakages...
 
Java tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry LevelJava tutorial for Beginners and Entry Level
Java tutorial for Beginners and Entry Level
 
Java 102 intro to object-oriented programming in java - exercises
Java 102   intro to object-oriented programming in java - exercisesJava 102   intro to object-oriented programming in java - exercises
Java 102 intro to object-oriented programming in java - exercises
 
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
Java Class 6 | Java Class 6 |Threads in Java| Applets | Swing GUI | JDBC | Ac...
 
Java For beginners and CSIT and IT students
Java  For beginners and CSIT and IT studentsJava  For beginners and CSIT and IT students
Java For beginners and CSIT and IT students
 
Core java concepts
Core java  conceptsCore java  concepts
Core java concepts
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
 
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
Collection Framework in Java | Generics | Input-Output in Java | Serializatio...
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
 
Java basic
Java basicJava basic
Java basic
 
Core java
Core javaCore java
Core java
 
Core java
Core java Core java
Core java
 
An Introduction to Scala for Java Developers
An Introduction to Scala for Java DevelopersAn Introduction to Scala for Java Developers
An Introduction to Scala for Java Developers
 
Object Oriented Programming in PHP
Object Oriented Programming in PHPObject Oriented Programming in PHP
Object Oriented Programming in PHP
 
Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2Core Java Programming | Data Type | operator | java Control Flow| Class 2
Core Java Programming | Data Type | operator | java Control Flow| Class 2
 
Object Oriented Programming C#
Object Oriented Programming C#Object Oriented Programming C#
Object Oriented Programming C#
 

Similar to The Dark Side of Objective-C

Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java DevelopersMuhammad Abdullah
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
Dhaval Kaneria
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
kenatmxm
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
Diksha Bhargava
 
Objective-C Runtime overview
Objective-C Runtime overviewObjective-C Runtime overview
Objective-C Runtime overview
Fantageek
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
Amr Elghadban (AmrAngry)
 
Objective c
Objective cObjective c
Objective c
ricky_chatur2005
 
Static analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesStatic analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutes
Andrey Karpov
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rdConnex
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtimeDneprCiklumEvents
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
Software Productivity Strategists, Inc
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1stConnex
 
python.pptx
python.pptxpython.pptx
python.pptx
Dhanushrajucm
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
Kazunobu Tasaka
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
Vibrant Technologies & Computers
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
paramisoft
 
Advanced oops concept using asp
Advanced oops concept using aspAdvanced oops concept using asp
Advanced oops concept using asp
shenbagavallijanarth
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
ThoughtWorks
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
Usman Mehmood
 
Black magic and swizzling in Objective-C
Black magic and swizzling in Objective-CBlack magic and swizzling in Objective-C
Black magic and swizzling in Objective-C
Ben Gotow
 

Similar to The Dark Side of Objective-C (20)

Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
 
Objective-C for iOS Application Development
Objective-C for iOS Application DevelopmentObjective-C for iOS Application Development
Objective-C for iOS Application Development
 
Intro to iOS Development • Made by Many
Intro to iOS Development • Made by ManyIntro to iOS Development • Made by Many
Intro to iOS Development • Made by Many
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Objective-C Runtime overview
Objective-C Runtime overviewObjective-C Runtime overview
Objective-C Runtime overview
 
01 objective-c session 1
01  objective-c session 101  objective-c session 1
01 objective-c session 1
 
Objective c
Objective cObjective c
Objective c
 
Static analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutesStatic analysis: Around Java in 60 minutes
Static analysis: Around Java in 60 minutes
 
Presentation 3rd
Presentation 3rdPresentation 3rd
Presentation 3rd
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
 
Java Reflection Concept and Working
Java Reflection Concept and WorkingJava Reflection Concept and Working
Java Reflection Concept and Working
 
Presentation 1st
Presentation 1stPresentation 1st
Presentation 1st
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Working with Cocoa and Objective-C
Working with Cocoa and Objective-CWorking with Cocoa and Objective-C
Working with Cocoa and Objective-C
 
PHP - Introduction to Object Oriented Programming with PHP
PHP -  Introduction to  Object Oriented Programming with PHPPHP -  Introduction to  Object Oriented Programming with PHP
PHP - Introduction to Object Oriented Programming with PHP
 
iOS development introduction
iOS development introduction iOS development introduction
iOS development introduction
 
Advanced oops concept using asp
Advanced oops concept using aspAdvanced oops concept using asp
Advanced oops concept using asp
 
Bootstrapping iPhone Development
Bootstrapping iPhone DevelopmentBootstrapping iPhone Development
Bootstrapping iPhone Development
 
Object oriented javascript
Object oriented javascriptObject oriented javascript
Object oriented javascript
 
Black magic and swizzling in Objective-C
Black magic and swizzling in Objective-CBlack magic and swizzling in Objective-C
Black magic and swizzling in Objective-C
 

Recently uploaded

2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
Łukasz Chruściel
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
vrstrong314
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Crescat
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Neo4j
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
Alina Yurenko
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
lorraineandreiamcidl
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
NYGGS Automation Suite
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
QuickwayInfoSystems3
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
abdulrafaychaudhry
 

Recently uploaded (20)

2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf2024 eCommerceDays Toulouse - Sylius 2.0.pdf
2024 eCommerceDays Toulouse - Sylius 2.0.pdf
 
OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024OpenMetadata Community Meeting - 5th June 2024
OpenMetadata Community Meeting - 5th June 2024
 
Nidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, TipsNidhi Software Price. Fact , Costs, Tips
Nidhi Software Price. Fact , Costs, Tips
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
Introducing Crescat - Event Management Software for Venues, Festivals and Eve...
 
Vitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdfVitthal Shirke Java Microservices Resume.pdf
Vitthal Shirke Java Microservices Resume.pdf
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Atelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissancesAtelier - Innover avec l’IA Générative et les graphes de connaissances
Atelier - Innover avec l’IA Générative et les graphes de connaissances
 
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)GOING AOT WITH GRAALVM FOR  SPRING BOOT (SPRING IO)
GOING AOT WITH GRAALVM FOR SPRING BOOT (SPRING IO)
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOMLORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
LORRAINE ANDREI_LEQUIGAN_HOW TO USE ZOOM
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket ManagementUtilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
Utilocate provides Smarter, Better, Faster, Safer Locate Ticket Management
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Enterprise Resource Planning System in Telangana
Enterprise Resource Planning System in TelanganaEnterprise Resource Planning System in Telangana
Enterprise Resource Planning System in Telangana
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Enterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptxEnterprise Software Development with No Code Solutions.pptx
Enterprise Software Development with No Code Solutions.pptx
 
Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)Introduction to Pygame (Lecture 7 Python Game Development)
Introduction to Pygame (Lecture 7 Python Game Development)
 

The Dark Side of Objective-C

  • 1. The Dark Side of Objective-C Martin Kiss | kish | @Tricertops PixelCut s. r. o.
  • 2. Objective-C Runtime Creates illusion of objects and messages
  • 5. What is Runtime? • C support library • Manages classes and methods • Handles method invocations • Memory management routines • Manages lifetime of weak references
  • 6. Why should Swift care? • Swift is a new syntax for Objective-C • Frameworks are all in Objective-C • NSObject and @objc • Many of things are not possible, yet • Swift will need its own runtime
  • 7. What needs runtime? • NSCoding • Storyboards & XIBs • Key-Value Coding • Key-Value Observing • Core Animation • Testing & Mocking • Core Data • NSProxy • UIAppearance • NSUndoManager • Cocoa Bindings • UIResponder
  • 10. Look up Class by Name High Level Low Level
 How It Works
 Used By NSClassFromString() objc_getClass()
 objc_lookUpClass() Runtime holds a table of all classes by their names as keys NSCoding, Storyboards, XIBs
  • 11. Perform Selector by Name High Level
 Low Level
 How It Works
 Used By
 NSSelectorFromString()
 -performSelector: sel_registerName()
 objc_msgSend() Classes store method implementations in tables by selectors as keys Key-Value Coding, Storyboards, XIBs, UIControl, UIGestureRecognizer
  • 12. Store Associated Objects Functions
 How It Works
 What Is It For
 
 
 
 Used By
 objc_getAssociatedObject()
 objc_setAssociatedObject() Runtime holds side-table for each object until it deallocates Adding storage to objects without adding ivars, for example rarely used values UIViews, Auto Layout, UIAppearance, many more
  • 14. Access Ivars by Name Functions
 How It Works
 
 Used By class_getInstanceVariable()
 class_setInstanceVariable() Instance variables are accessed indirectly and classes contain lookup table Key-Value Coding, Key-Value Observing
  • 15. Access Attributes of Properties Functions
 How It Works
 What Is It For
 
 
 Used By class_getProperty()
 property_getAttributes() Classes include all info about properties, like name, attributes, and backing ivar Check if property is weak or strong or if the property has ivar Custom CALayer animatable properties
  • 16. Enumerate Ivars & Properties Functions
 How It Works
 What Is It For
 
 Used By
 class_copyIvarList()
 class_copyPropertyList() Classes include tables and metadata for ivars and properties Inspection of object contents CALayer animatable properties, Core Image Filters, automatic descriptions
  • 17. Enumerate Methods Function How It Works
 What Is It For
 
 Used By class_copyMethodList() Classes include table of methods with their selectors and implementations Find methods that match a pattern Tests & Mocks, UIAppearance
  • 18. Enumerate Classes Functions
 How It Works
 What Is It For
 objc_copyClassList()
 objc_copyClassNamesForImage() Runtime holds table of all classes loaded in your process, per executable Find classes that match a pattern, find all subclasses of a class ⚠ Warning: Accessing framework classes will trigger side effects!
  • 19. Sending Messages Function Related
 How It Works
 What Is It For
 objc_msgSend() -methodForSelector:
 -methodSignatureForSelector: All [bracket calls] are translated to objc_msgSend() Perform selectors when standard method
 -performSelector: is not enough ⚠ Warning: Requires casting to work properly!
  • 20. Sending Messages How it works? - (void)updateTitle:(NSString *)title { title = title.trimmedString;
 self.title = title;
 self.navigationBar.title = title;
 }
  • 21. Sending Messages Components of a method updateTitle: void, id, SEL, NSString * { title = title.trimmedString;
 self.title = title;
 self.navigationBar.title = title;
 }
  • 22. Selector Type Signature Implementation Sending Messages Components of a method updateTitle: void, id, SEL, id void func(id self, SEL _cmd, id title) { title = title.trimmedString;
 self.title = title;
 self.navigationBar.title = title;
 } SEL IMP "v@:@"
  • 23. Sending Messages [object updateTitle:@"Hello"]; let message = void(*)(id,SEL,id)&objc_msgSend; SEL selector = @selector(updateTitle:); message(object, selector, @"Hello"); =
  • 24. Expert Runtime Services learn t|he powER of t|he dark Side!
  • 26. Add Methods to Classes Function Override
 What Is It For
 Used By
 class_addMethod() +resolveInstanceMethod:
 +resolveClassMethod: Implement methods on demand, for example getters of @dynamic properties Core Data, CALayer animatable properties, UIAppearance, KVO
  • 27. Replace Implementations Functions
 
 Override What Is It For
 Used By
 class_replaceMethod()
 method_setImplementation()
 method_exchangeImplementations() +load in categories Extend existing framework classes with
 new behaviors UIAppearance, Key-Value Observing,
 Mocking frameworks ⚠ Warning: It is not trivial to implement method swizzling properly!
  • 28. Forward Invocations Override
 
 How It Works
 What Is It For
 
 Used By -forwardInvocation: Unrecognized selectors are passed into this method before they throw exception Simulate multiple inheritance, forward methods to internal components, modify arguments NSProxy subclasses, NSUndoManager
  • 29. Change Class of Object Functions
 
 How It Works
 What Is It For
 Used By object_setClass() Object has ivar isa, which points to the class and is used for method lookup Extend behavior of a single object, not all objects of that class Key-Value Observing, Core Data ⚠ Warning: New class should handle all methods of original class!
  • 30. Create New Classes Functions
 
 
 How It Works
 What Is It For
 Used By objc_allocateClassPair()
 objc_registerClassPair() Allocate, add methods, ivars, properties, and then register in runtime Customize class methods or for using with object_setClass() Key-Value Observing, Core Data
  • 31. self MyClass lookup message What is Metaclass? Implementations are looked up in class Instance Methods
  • 32. self MyClass MyMetaClass lookup lookup message message Instance Methods Class Methods What is Metaclass? Class is also an object, so it has a class
  • 34. How much is it used? Measured using symbolic breakpoints
  • 35. Minimal Swift App import UIKit~~~~~~~~~~~~~~~ @UIApplicationMain~~~~~~~~~~~~~~~
 class AppDelegate: NSObject,~~~~~~~~~~~~~~~
 UIApplicationDelegate {} • Initializes UIApplication & Main Run Loop • No launch Storyboard or XIB
  • 36. Minimal Swift App Look up Class 608× Look up Selector 718× Get / Set Associated Object 254× / 179× Copy Method List 378× Add / Change Method 13× / 1× Create Class 13×
  • 37. iOS Dash App • Documentation viewer • Standard UI components • UIKit & WebKit • 20k LOC of Objective-C
  • 38. iOS Dash App Look up Class 1357× Look up Selector 1283× Get / Set Associated Object 2803× / 1317× Copy Method List 515× Add / Change Method 87× / 14× Create Class 18×
  • 39. iOS Kickstarter App • Crowdfunding app • Customized UI • 120k LOC of mixed code
  • 40. iOS Kickstarter App Look up Class 2813× Look up Selector 1455× Get / Set Associated Object 4375× / 1966× Copy Method List 496× Add / Change Method 190× / 10× Create Class 20×
  • 41. PaintCode • Vector drawing Mac app • Custom complex UI • 300k LOC of Objective-C • XIBs with Cocoa Bindings
  • 42. PaintCode Look up Class 41189× Look up Selector 9615× Get / Set Associated Object 45230× / 2045× Copy Method List 370× Add / Change Method 664× / 1× Create Class 112×
  • 43. Ask me anything Thank You Martin Kiss | kish | @Tricertops PixelCut s. r. o.