Re: Several questions
Re: Several questions
- Subject: Re: Several questions
- From: Vince DeMarco <email@hidden>
- Date: Fri, 6 Jul 2001 15:49:34 -0700
On Friday, July 6, 2001, at 12:28 AM, jgo wrote:
From: "John C. Randolph" <email@hidden>
Date: 2001 July 02 21:11:36 -0700
On Monday, 2001 July 02 at 18:26, Hisaoki Nishida wrote:
I have some general questions about Cocoa programming...
2. What's the difference between - and + (in method declarations)?
- means an instance method. + means a class method.
Well, I know what a class is, and I know what an instance is,
but what is an "instance method" as opposed to a "class method"?
I never considered the possibility that a method would be
instantiated, as contrasted with data members/instance variables.
instance method is a method you send to an instance of a class
like this say you have a class called MyObject and here is the header
file
@interface MyObject : NSObject
{
}
+ classMethod;
+ (BOOL)isSomethingOkay;
- instanceMethod;
@end
a classMethod is a message you send to the class object (there is only
one MyObject
class in the application)
so in your code
[MyObject classMethod] or
if ([MyObject isSomethingOkay] == YES){
NSLog(@"All is well");
}
The instance method is a message you send to a particular instance of a
class
MyObject *instance1;
MyObject *instance2;
instance1= [[MyObject alloc] init];
instance2 = [[MyObject alloc] init];
[instance1 instanceMethod]
[instance2 instanceMethod]
does this help now??
vince