0

We can use object of AppDelegate by these ways say...

1)

AppDelegate *app; // Globally declared

app = (AppDelegate*)[[UIApplication sharedApplication] delegate]; //Use this any where in app

2)

#define     APP_DELEGATE ((AppDelegate*)[[UIApplication sharedApplication] delegate]) 

[APP_DELEGATE.navigationController ...]; //use macro any where in app

I want to know which way is better in terms of performance and processing speed ?

βhargavḯ
  • 9,786
  • 1
  • 37
  • 59
  • 1
    If you assign the delegate once to a global variable and than access this variable everytime you need your appdelegate is faster than the macro... but this should not realy be your concern as i can't hardly imagine this changes the overall performance of your application in any way. – Jonathan Cichon Apr 15 '13 at 09:09
  • I think macro is faster then Inline function read http://www.codeproject.com/Articles/8376/Function-like-Macros-vs-Inline-Functions and http://stackoverflow.com/questions/5226803/inline-function-v-macro-in-c-whats-the-overhead-memory-speed – iPatel Apr 15 '13 at 09:15

2 Answers2

2

Don't think it will change the performance. It's just more a utility than anything else honestly.

Rui Peres
  • 25,741
  • 9
  • 87
  • 137
2

Neither method will be the limiting factor on the performance of your application. Write for clarity, readability and good structure first.

Don't try and make "performance enhancements" by looking at the number of method calls that are used. Method calls are practically free, unless you're doing millions of them.

If you are talking to the app delegate from everywhere often enough to worry about the speed of access, then you've made a terrible error in the design and implementation of your app.

By "often enough to worry about the speed of access" I mean that Instruments (you are using Instruments, right? You can't worry about or improve your app's performance without using it) is telling you that getting a reference to the app delegate is your current performance bottleneck.

jrturton
  • 118,105
  • 32
  • 252
  • 268