SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Objective-c Tricks
1
2 0 1 4 – Jan
B y : H o s s a m G h a r e e b
2
Use Literals
 The following is the old way of writing
code:
3
The same code can be written
as follows:
Subscripting
 You can use subscripting to access the
values inside dictionaries and arrays. This
is how the syntax looks:
4
Classes And Selectors From
Strings
 We can dynamically generate classes and
selectors from strings, We do this by using
the NSClassFromString and
NSSelectorFromString functions:
 NSClassFromString will return nil if there isn't a class
in the runtime that matches the string
5
 We can also decide in run time which selector to be called
based on input:
* Required 6
Method Swizzling
 Methods are made up of two components. The selector, which is an
identifier for a method, and the IMP, which is the actual implementation
that is run. One of the key things about this separation is that a selector
and IMP link can be changed. One IMP can have multiple selectors
pointing to it.
 Subclassing -> This allows you to override a method and call the original
implementation, but it means that you have to use instances of this
subclass.
 Category -> you cannot call the original implementation if you override
a method.
 Swizzling -> You can override a method without subclassing AND call
the original implementation
* Required 7
Example
 make a UINavigationBar green
 this will change all navigation bars in the app to
green, but if I used UIImagePickerController it will
be changed too!!!. We have to find new way for
that >>>>> Method Swizzling
8
Method Swizzling Cont.
 Method swizzling, in short, is switching methods at runtime. So
you can say for UINavigationBar don’t use the
standard drawRect:, but instead swap it with a different one
* Required 9
 Here is the swizzling:
10
Another problem solved by Swizzling
 measure how long the synchronize takes in
NSUserDefaults
* Required 11
Cont.
12
Example
 Borders around all UIViews
 initWithFrame: get a red border, views
that were unarchived (for example as
part of XIBs) get a blue border.
13
Surprise 
the status bar at the top of
an iOS app is drawn by
the app itself
14
How to do that ?
* Required 15
Cont.
* Required 16
Other tricks
 objc_msgSend()
This function takes a target, a selector and
a list of arguments
17
CGRect Tricks
 Shrink CGRect:
 Different insets for each edge:
using UIEdgeInsets(top, left, bottom, right)
18
Cont.
 CGRectUnion is UIScrollView’s best friend:
if you want use UIScrollView with bunch of
subviews, so you have to know only the top-left
and bottom-right views:
19
Cont.
 Dictionary Representation (to store in in plist on disk):
20
Print CGRect values :
Cont.
 Storing it in Obj-C Storage Classes
21
Thank you
Any Questions?
22

Weitere ähnliche Inhalte

Andere mochten auch

Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchMatteo Battaglio
 
Hackatron - UIKit Dynamics
Hackatron - UIKit DynamicsHackatron - UIKit Dynamics
Hackatron - UIKit DynamicsRenzo G. Pretto
 
iOS中Lua脚本的应用
iOS中Lua脚本的应用iOS中Lua脚本的应用
iOS中Lua脚本的应用Proteas Wang
 
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en增强 杜
 
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例Justin Lee
 
20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介Justin Lee
 
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011Android Application Development at JFokus 2011
Android Application Development at JFokus 2011Anders Göransson
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatchcqtt191
 
iOS Multithreading
iOS MultithreadingiOS Multithreading
iOS MultithreadingRicha Jain
 
CS193P Lecture 5 View Animation
CS193P Lecture 5 View AnimationCS193P Lecture 5 View Animation
CS193P Lecture 5 View Animationonoaonoa
 
iOS Application Lifecycle
iOS Application LifecycleiOS Application Lifecycle
iOS Application LifecycleSiva Prasad K V
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricksjimi-c
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview QuestionsClark Davidson
 
Multithreading and Parallelism on iOS [MobOS 2013]
 Multithreading and Parallelism on iOS [MobOS 2013] Multithreading and Parallelism on iOS [MobOS 2013]
Multithreading and Parallelism on iOS [MobOS 2013]Kuba Břečka
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCDrsebbe
 
Extending Titanium with native iOS and Android modules
Extending Titanium with native iOS and Android modules Extending Titanium with native iOS and Android modules
Extending Titanium with native iOS and Android modules omorandi
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerVineet Kumar Saini
 

Andere mochten auch (19)

Objective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central DispatchObjective-C Blocks and Grand Central Dispatch
Objective-C Blocks and Grand Central Dispatch
 
Hackatron - UIKit Dynamics
Hackatron - UIKit DynamicsHackatron - UIKit Dynamics
Hackatron - UIKit Dynamics
 
iOS中Lua脚本的应用
iOS中Lua脚本的应用iOS中Lua脚本的应用
iOS中Lua脚本的应用
 
Intro to appcelerator
Intro to appceleratorIntro to appcelerator
Intro to appcelerator
 
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
基于Cocos2 d x二次开发的自有引擎方案分享-mobile 2d framework en
 
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
2011/08/20跨平台行動應用程式使用者介面開發—以titanium mobile為例
 
20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介20110525[Taipei GTUG] titanium mobile簡介
20110525[Taipei GTUG] titanium mobile簡介
 
Android Application Development at JFokus 2011
Android Application Development at JFokus 2011Android Application Development at JFokus 2011
Android Application Development at JFokus 2011
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
iOS Multithreading
iOS MultithreadingiOS Multithreading
iOS Multithreading
 
CS193P Lecture 5 View Animation
CS193P Lecture 5 View AnimationCS193P Lecture 5 View Animation
CS193P Lecture 5 View Animation
 
iOS Application Lifecycle
iOS Application LifecycleiOS Application Lifecycle
iOS Application Lifecycle
 
AnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and TricksAnsibleFest 2014 - Role Tips and Tricks
AnsibleFest 2014 - Role Tips and Tricks
 
iOS Developer Interview Questions
iOS Developer Interview QuestionsiOS Developer Interview Questions
iOS Developer Interview Questions
 
Multithreading and Parallelism on iOS [MobOS 2013]
 Multithreading and Parallelism on iOS [MobOS 2013] Multithreading and Parallelism on iOS [MobOS 2013]
Multithreading and Parallelism on iOS [MobOS 2013]
 
Blocks & GCD
Blocks & GCDBlocks & GCD
Blocks & GCD
 
Extending Titanium with native iOS and Android modules
Extending Titanium with native iOS and Android modules Extending Titanium with native iOS and Android modules
Extending Titanium with native iOS and Android modules
 
Top C Language Interview Questions and Answer
Top C Language Interview Questions and AnswerTop C Language Interview Questions and Answer
Top C Language Interview Questions and Answer
 
C notes.pdf
C notes.pdfC notes.pdf
C notes.pdf
 

Ähnlich wie Objective C Tricks

Javascript Deofuscation A manual Approach
Javascript Deofuscation A manual ApproachJavascript Deofuscation A manual Approach
Javascript Deofuscation A manual ApproachGregory Hanis
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurementsTuba Tanveer
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx javaCongTrung Vnit
 
Apply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationApply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationGuo Albert
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstractionRaghav Chhabra
 
Inline function
Inline functionInline function
Inline functionTech_MX
 
DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...
DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...
DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...Felipe Prado
 
maXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO StandardmaXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO StandardMax Kleiner
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLAkhil Mittal
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaHamad Odhabi
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxpbilly1
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2Knoldus Inc.
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Umar Farooq
 

Ähnlich wie Objective C Tricks (20)

Abstraction
Abstraction Abstraction
Abstraction
 
Abstraction
AbstractionAbstraction
Abstraction
 
Javascript Deofuscation A manual Approach
Javascript Deofuscation A manual ApproachJavascript Deofuscation A manual Approach
Javascript Deofuscation A manual Approach
 
Cobol interview-questions
Cobol interview-questionsCobol interview-questions
Cobol interview-questions
 
Instrumentation and measurements
Instrumentation and measurementsInstrumentation and measurements
Instrumentation and measurements
 
Reactive programming with rx java
Reactive programming with rx javaReactive programming with rx java
Reactive programming with rx java
 
Apply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report ImplementationApply Template Method Pattern in Report Implementation
Apply Template Method Pattern in Report Implementation
 
Interface and abstraction
Interface and abstractionInterface and abstraction
Interface and abstraction
 
Inline function
Inline functionInline function
Inline function
 
C# features
C# featuresC# features
C# features
 
MVC
MVCMVC
MVC
 
DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...
DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...
DEF CON 23 - Topher Timzen and Ryan Allen - Hijacking Arbitrary NET App Contr...
 
Objective c slide I
Objective c slide IObjective c slide I
Objective c slide I
 
Designing Better API
Designing Better APIDesigning Better API
Designing Better API
 
maXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO StandardmaXbox Starter 43 Work with Code Metrics ISO Standard
maXbox Starter 43 Work with Code Metrics ISO Standard
 
LearningMVCWithLINQToSQL
LearningMVCWithLINQToSQLLearningMVCWithLINQToSQL
LearningMVCWithLINQToSQL
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docxSMP4 Thread Scheduler======================INSTRUCTIONS.docx
SMP4 Thread Scheduler======================INSTRUCTIONS.docx
 
Clean Code - Part 2
Clean Code - Part 2Clean Code - Part 2
Clean Code - Part 2
 
Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#Polymorphism, Abstarct Class and Interface in C#
Polymorphism, Abstarct Class and Interface in C#
 

Mehr von Inova LLC

MVVM presentation
MVVM presentationMVVM presentation
MVVM presentationInova LLC
 
Activities vs fragment
Activities vs fragmentActivities vs fragment
Activities vs fragmentInova LLC
 
Benefits of idea treasury
Benefits of idea treasuryBenefits of idea treasury
Benefits of idea treasuryInova LLC
 
Advertising
Advertising Advertising
Advertising Inova LLC
 
Market research
Market researchMarket research
Market researchInova LLC
 
Disc Personality Type
Disc Personality TypeDisc Personality Type
Disc Personality TypeInova LLC
 
UI vs UX workshop
UI vs UX workshopUI vs UX workshop
UI vs UX workshopInova LLC
 
Positive thinking
Positive thinkingPositive thinking
Positive thinkingInova LLC
 
Sketch app interface
Sketch app interfaceSketch app interface
Sketch app interfaceInova LLC
 
CSED 2018 Orientation
CSED 2018 OrientationCSED 2018 Orientation
CSED 2018 OrientationInova LLC
 
Mind map Introduction
Mind map IntroductionMind map Introduction
Mind map IntroductionInova LLC
 
Agile scheduling
Agile schedulingAgile scheduling
Agile schedulingInova LLC
 
Business plan
Business planBusiness plan
Business planInova LLC
 
Introduction to Sencha touch
Introduction to Sencha touchIntroduction to Sencha touch
Introduction to Sencha touchInova LLC
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to AgileInova LLC
 
Internet Presence
Internet PresenceInternet Presence
Internet PresenceInova LLC
 
Agile Planning for value
Agile Planning for valueAgile Planning for value
Agile Planning for valueInova LLC
 
Agile estimate size
Agile estimate sizeAgile estimate size
Agile estimate sizeInova LLC
 

Mehr von Inova LLC (20)

MVVM presentation
MVVM presentationMVVM presentation
MVVM presentation
 
Activities vs fragment
Activities vs fragmentActivities vs fragment
Activities vs fragment
 
Benefits of idea treasury
Benefits of idea treasuryBenefits of idea treasury
Benefits of idea treasury
 
Advertising
Advertising Advertising
Advertising
 
Market research
Market researchMarket research
Market research
 
Disc Personality Type
Disc Personality TypeDisc Personality Type
Disc Personality Type
 
UI vs UX workshop
UI vs UX workshopUI vs UX workshop
UI vs UX workshop
 
Positive thinking
Positive thinkingPositive thinking
Positive thinking
 
Sketch app interface
Sketch app interfaceSketch app interface
Sketch app interface
 
Inova
InovaInova
Inova
 
Inova
InovaInova
Inova
 
CSED 2018 Orientation
CSED 2018 OrientationCSED 2018 Orientation
CSED 2018 Orientation
 
Mind map Introduction
Mind map IntroductionMind map Introduction
Mind map Introduction
 
Agile scheduling
Agile schedulingAgile scheduling
Agile scheduling
 
Business plan
Business planBusiness plan
Business plan
 
Introduction to Sencha touch
Introduction to Sencha touchIntroduction to Sencha touch
Introduction to Sencha touch
 
Introduction to Agile
Introduction to AgileIntroduction to Agile
Introduction to Agile
 
Internet Presence
Internet PresenceInternet Presence
Internet Presence
 
Agile Planning for value
Agile Planning for valueAgile Planning for value
Agile Planning for value
 
Agile estimate size
Agile estimate sizeAgile estimate size
Agile estimate size
 

Kürzlich hochgeladen

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptxiammrhaywood
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)cama23
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 

Kürzlich hochgeladen (20)

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptxAUDIENCE THEORY -CULTIVATION THEORY -  GERBNER.pptx
AUDIENCE THEORY -CULTIVATION THEORY - GERBNER.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)Global Lehigh Strategic Initiatives (without descriptions)
Global Lehigh Strategic Initiatives (without descriptions)
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 

Objective C Tricks

  • 1. Objective-c Tricks 1 2 0 1 4 – Jan B y : H o s s a m G h a r e e b
  • 2. 2 Use Literals  The following is the old way of writing code:
  • 3. 3 The same code can be written as follows:
  • 4. Subscripting  You can use subscripting to access the values inside dictionaries and arrays. This is how the syntax looks: 4
  • 5. Classes And Selectors From Strings  We can dynamically generate classes and selectors from strings, We do this by using the NSClassFromString and NSSelectorFromString functions:  NSClassFromString will return nil if there isn't a class in the runtime that matches the string 5
  • 6.  We can also decide in run time which selector to be called based on input: * Required 6
  • 7. Method Swizzling  Methods are made up of two components. The selector, which is an identifier for a method, and the IMP, which is the actual implementation that is run. One of the key things about this separation is that a selector and IMP link can be changed. One IMP can have multiple selectors pointing to it.  Subclassing -> This allows you to override a method and call the original implementation, but it means that you have to use instances of this subclass.  Category -> you cannot call the original implementation if you override a method.  Swizzling -> You can override a method without subclassing AND call the original implementation * Required 7
  • 8. Example  make a UINavigationBar green  this will change all navigation bars in the app to green, but if I used UIImagePickerController it will be changed too!!!. We have to find new way for that >>>>> Method Swizzling 8
  • 9. Method Swizzling Cont.  Method swizzling, in short, is switching methods at runtime. So you can say for UINavigationBar don’t use the standard drawRect:, but instead swap it with a different one * Required 9
  • 10.  Here is the swizzling: 10
  • 11. Another problem solved by Swizzling  measure how long the synchronize takes in NSUserDefaults * Required 11
  • 13. Example  Borders around all UIViews  initWithFrame: get a red border, views that were unarchived (for example as part of XIBs) get a blue border. 13
  • 14. Surprise  the status bar at the top of an iOS app is drawn by the app itself 14
  • 15. How to do that ? * Required 15
  • 17. Other tricks  objc_msgSend() This function takes a target, a selector and a list of arguments 17
  • 18. CGRect Tricks  Shrink CGRect:  Different insets for each edge: using UIEdgeInsets(top, left, bottom, right) 18
  • 19. Cont.  CGRectUnion is UIScrollView’s best friend: if you want use UIScrollView with bunch of subviews, so you have to know only the top-left and bottom-right views: 19
  • 20. Cont.  Dictionary Representation (to store in in plist on disk): 20 Print CGRect values :
  • 21. Cont.  Storing it in Obj-C Storage Classes 21