User |
Post |
6:39 am
August 14, 2008
|
Uhu
iCoder
|
|
|
|
|
posts 17
|
|
|
Hi,
can anyone tell me what the AppDelegate does and why it is there?
I have problems understanding this line:
FruitAppDelegate *appDelegate = (FruitAppDelegate *)[[UIApplication sharedApplication] delegate];
|
|
|
7:39 am
August 14, 2008
|
crazyiez
iCoder
|
|
|
|
|
posts 30
|
|
|
For that you are just making a variable called appDelegate
kind of like when i do this.
NSNumber *number = [NSNumber alloc] initWithint: 5];
im creating a instance of NSNumber called number, then I am allocating it and setting it with the number 5. So i can use it later. like add 5 more to it.
So for that your creating a instance of FruitAppDelegate and the rest of that code i dont know.
P.S. you might want to edit your other topic you accidentally made two of them.
|
|
7:42 am
August 14, 2008
|
Admin
|
|
brandontreb
|
|
|
posts 88
|
|
|
The AppDelegate is basically your application's controller. It is where execution begins (other than main.m). That line was put into place to access the AppDelegate object. This was to get a reference to the “fruits” array. The “fruits” array was declared inside of our application's delegate.
Here it is line by line
FruitAppDelegate *appDelegate // Declaring an object to hold the reference to the applicaiton's appDelegate
(FruitAppDelegate *) // We are casting the return value of the next phrase to a FruitAppDelegate
[[UIApplication sharedApplication] delegate] // This gives us a reference to the appDelegate for the whole application
now that the appDelegate object holds a reference to the application's appDelegate object, we can access variables that are declared inside of it. This allows us to do things like [appDelegate.fruits count] which will return the number of fruits in the array.
I hope that helps…
|
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra
|
|
7:44 am
August 14, 2008
|
crazyiez
iCoder
|
|
|
|
|
posts 30
|
|
|
Brandon said:
FruitAppDelegate *appDelegate // Declaring an object to hold the reference to the applicaiton's appDelegate
I was sortof right. Thanks for the better explination r u really creating a new object or just making a instance of the it?
|
|
7:46 am
August 14, 2008
|
Admin
|
|
brandontreb
|
|
|
posts 88
|
|
|
We are just making a reference to it as there should only be one appDelegate per application. There would be no need to create a new instance of it.
|
If debugging is the process of removing bugs, then programming must be the process of putting them in.
-Edsger Dijkstra
|
|
8:15 am
August 14, 2008
|
crazyiez
iCoder
|
|
|
|
|
posts 30
|
|
|
Brandon said:
We are just making a reference to it as there should only be one appDelegate per application. There would be no need to create a new instance of it.
Ahhh okay… i need to pay attention to semantics a bit more… thanks
|
|
11:23 am
August 15, 2008
|
jazzmic
iCoder
|
|
|
|
|
posts 6
|
|
|
Just to make sure… when there is an aplicaction with many views, each can have it's own viewcontroller but still only one appDelegate? I'm having problems understanding the MVC model…
Thanks
|
|
9:22 pm
August 21, 2008
|
kgrimes
Noob
|
|
Lewes, UK
|
|
|
posts 2
|
|
|
Me too! It has taken a frikkin age to get my head around the MVC model, delegates, vie controllers, etc etc.
I'm currently working my way through Aaron Hillegass's book 'Cocoa Programming for Mac Os X, 3rd Ed', which is the best text I've found so far. Also got a couple of Cocoa podcasts to try out.
I can't wait until we get some dedicated iPhone programming books out, as it has been slow progress for me. My Objective-C is fine, it's just the whole connections/Interface Builder thing 
Keith
|
|