Re: Obj-C, class methods and instance methods
Re: Obj-C, class methods and instance methods
- Subject: Re: Obj-C, class methods and instance methods
- From: "Clark S. Cox III" <email@hidden>
- Date: Sun, 19 May 2002 13:33:13 -0400
On 05/19/2002 13:12, "Sanj W." <email@hidden> wrote:
>
Hi,
>
>
Im trying to understand the difference between class methods and instance
>
methods in Obj-C. I thought that class methods are similar to static methods
>
in Java, where one could call the method without instantiating an class.
Correct
>
However, I could write the following class without a constructor (init) and
>
have an instance method (an IBAction) and get the system to call it (by
>
merely connecting in IB).
>
>
* How does this work? It would have made sense to me if myAction was
>
declared as a class method.
Anything that you can connect to in IB is an instance, not a class, so
it doesn't make sense to have IBActions declared as class methods.
>
>
+(IBAction)myAction:(id)sender
>
>
* Is there a default constructor in in the following class that I declared?
Yes and no. Objective-C does not have constructors, however as per
convention, the init method is *like* a constructor. If you don't provide an
init method, then the superclass' init method is called instead, which is
exactly what you would want if you didn't need any extra initialization on
top of what NSObject does.
--
Clark S. Cox III
http://clarkcox.dyndns.org/
email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.