SlideShare une entreprise Scribd 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.

Contenu connexe

Tendances

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
 
Java notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esectionJava notes(OOP) jkuat IT esection
Java notes(OOP) jkuat IT esection
Arc Keepers Solutions
 
camel-scala.pdf
camel-scala.pdfcamel-scala.pdf
camel-scala.pdf
Hiroshi Ono
 
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
 
Ruby object model
Ruby object modelRuby object model
Ruby object model
Chamnap Chhorn
 
Java basic
Java basicJava basic
Java basic
Sonam Sharma
 
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
 

Tendances (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#
 

Similaire à The Dark Side of Objective-C

Objective-c for Java Developers
Objective-c for Java DevelopersObjective-c for Java Developers
Objective-c for Java Developers
Muhammad 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 3rd
Connex
 
Pavel kravchenko obj c runtime
Pavel kravchenko obj c runtimePavel kravchenko obj c runtime
Pavel kravchenko obj c runtime
DneprCiklumEvents
 
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 1st
Connex
 
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
 

Similaire à 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
 

Dernier

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Łukasz Chruściel
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
rodomar2
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
Green Software Development
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
VALiNTRY360
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Julian Hyde
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
ssuserad3af4
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
ICS
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
XfilesPro
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
Drona Infotech
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
Marcin Chrost
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
Drona Infotech
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
dakas1
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
devvsandy
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
Ayan Halder
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
TheSMSPoint
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
Octavian Nadolu
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
SOCRadar
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
Rakesh Kumar R
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
Alberto Brandolini
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
mz5nrf0n
 

Dernier (20)

Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️Need for Speed: Removing speed bumps from your Symfony projects ⚡️
Need for Speed: Removing speed bumps from your Symfony projects ⚡️
 
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CDKuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
KuberTENes Birthday Bash Guadalajara - Introducción a Argo CD
 
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, FactsALGIT - Assembly Line for Green IT - Numbers, Data, Facts
ALGIT - Assembly Line for Green IT - Numbers, Data, Facts
 
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdfTop Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
Top Benefits of Using Salesforce Healthcare CRM for Patient Management.pdf
 
Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)Measures in SQL (SIGMOD 2024, Santiago, Chile)
Measures in SQL (SIGMOD 2024, Santiago, Chile)
 
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
316895207-SAP-Oil-and-Gas-Downstream-Training.pptx
 
Webinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for EmbeddedWebinar On-Demand: Using Flutter for Embedded
Webinar On-Demand: Using Flutter for Embedded
 
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
Everything You Need to Know About X-Sign: The eSign Functionality of XfilesPr...
 
Mobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona InfotechMobile App Development Company In Noida | Drona Infotech
Mobile App Development Company In Noida | Drona Infotech
 
Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !Enums On Steroids - let's look at sealed classes !
Enums On Steroids - let's look at sealed classes !
 
Mobile app Development Services | Drona Infotech
Mobile app Development Services  | Drona InfotechMobile app Development Services  | Drona Infotech
Mobile app Development Services | Drona Infotech
 
一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理一比一原版(USF毕业证)旧金山大学毕业证如何办理
一比一原版(USF毕业证)旧金山大学毕业证如何办理
 
Top 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptxTop 9 Trends in Cybersecurity for 2024.pptx
Top 9 Trends in Cybersecurity for 2024.pptx
 
Using Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional SafetyUsing Xen Hypervisor for Functional Safety
Using Xen Hypervisor for Functional Safety
 
Transform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR SolutionsTransform Your Communication with Cloud-Based IVR Solutions
Transform Your Communication with Cloud-Based IVR Solutions
 
Artificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension FunctionsArtificia Intellicence and XPath Extension Functions
Artificia Intellicence and XPath Extension Functions
 
socradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdfsocradar-q1-2024-aviation-industry-report.pdf
socradar-q1-2024-aviation-industry-report.pdf
 
How to write a program in any programming language
How to write a program in any programming languageHow to write a program in any programming language
How to write a program in any programming language
 
Modelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - AmsterdamModelling Up - DDDEurope 2024 - Amsterdam
Modelling Up - DDDEurope 2024 - Amsterdam
 
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
在线购买加拿大英属哥伦比亚大学毕业证本科学位证书原版一模一样
 

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.