1 Replies - 1594 Views - Last Post: 21 July 2012 - 10:43 AM

#1 Jakesta42  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 20-July 12

Objective C Instantiation of Objects Question

Posted 21 July 2012 - 10:40 AM

Hey guys,

So I'm new to this site, not really sure what the conventions are for how to go about asking a question, but I'm just beginning with Objective-C and have a question relating to the instantiating of objects.

Okay, so I know that the root class NSObject has the class methods alloc and init, and these methods are passed down to any classes that inherit NSObject, which is pretty much every class. I know the typical format for instantiating an object is like this:


 MyObject *m = [[MyObject alloc]init];  



But considering MyObject has the alloc and init methods inherited from NSObject, this could also theoretically work, considering that MyObject and NSObject have the same alloc and init methods (assuming that the class doesn't override them):


 MyObject *m = [[NSObject alloc] init]; 



And it works for just instantiating, but when I try to call any method in the MyObject class, an NSException is thrown. When I switch the NSObject alloc back to MyObject alloc, it works. I just don't understand why! This is probably a basic question, but any explanation?

Thanks in advance!

Jake

Is This A Good Question/Topic? 0
  • +

Replies To: Objective C Instantiation of Objects Question

#2 GunnerInc  Icon User is offline

  • "Hurry up and wait"
  • member icon




Reputation: 858
  • View blog
  • Posts: 2,276
  • Joined: 28-March 11

Re: Objective C Instantiation of Objects Question

Posted 21 July 2012 - 10:43 AM

Moving to Objective-C
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1