You must be logged in to post Login Register

Search 

AppDelegate

User Post

6:39 am
August 14, 2008


Uhu

Member

posts 17

1

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

Member

Wright State University

posts 30

2

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


Brandon

Admin

brandontreb

posts 48

3

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…

7:44 am
August 14, 2008


crazyiez

Member

Wright State University

posts 30

4

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 :P r u really creating a new object or just making a instance of the it?

7:46 am
August 14, 2008


Brandon

Admin

brandontreb

posts 48

5

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. 

8:15 am
August 14, 2008


crazyiez

Member

Wright State University

posts 30

6

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

Member

posts 6

7

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

New Member

Lewes, UK

posts 2

8

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 Yell

Keith


About the iCodeBlog forum

Currently Online:

3 Guests

Maximum Online: 7

Forums:

Groups: 2

Forums: 6

Topics: 73

Posts: 264

Members:

There are 144 members

There are 1 guests


Brandon has made 48 posts

Top Posters:

crazyiez - 30

Uhu - 17

Nick - 15

bobcubsfan - 11

rawnaveen - 7

Administrator: Brandon


© - Version 3.1.3 (Build 356)  

Share and Enjoy: