Subscribe ( )

iPhone Programming Tutorials

 

Forum

You must be logged in to post Login Register

Search 

Two ways to create an object ?

User Post

3:35 am
October 23, 2008


iCoder

Derbyshire, UK

posts 9

1

One little thing is puzzling me about creating an object from your own class. What is the difference between:

myClass *myObject;

and

myClass *myObject=[[myClass alloc] init];


5:45 am
October 23, 2008


AdeC

iCoder

posts 16

2

Im a noob too so here is my view (right or wrong!)

The first example if simply a variable declaration of an object type. i.e. it has not been instatiated yet.

The second is the same but the extra bit assigns the variable (myObject) to a new instance of type myClass. So [myClass alloc] allocates the memory for the object and init is a method call on myClass to initialise it.


Hope that makes sense (and is correct :) )


About the iCodeBlog forum

Currently Online:

6 Guests

Maximum Online: 19

Forums:

Groups: 2

Forums: 6

Topics: 165

Posts: 523

Members:

There are 278 members

There are 1 guests


Brandon has made 85 posts

Top Posters:

bobcubsfan - 49

crazyiez - 30

VertigoSol - 17

Uhu - 17

AdeC - 16

Administrator: Brandon | Moderators: VertigoSol


© - Version 3.1.4 (Build 357)  

Share and Enjoy: