• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Several questions
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Several questions (From: jgo <email@hidden>)

  • Prev by Date: XP discussion
  • Next by Date: Re: How to stop initial window ?
  • Previous by thread: Re: Several questions
  • Next by thread: Re: Several questions
  • Index(es):
    • Date
    • Thread