Take the 2-minute tour ×

Possible Duplicate:
Difference between “+” and “-” before function name in Objective-C

what does the mean about "+className" in Objective-C? The +className is a class method name. Thanks a lot.

share|improve this question
In what context? Give an example of where you see it being used. –  Alex Wayne Feb 3 '13 at 9:30
You mean a class method? –  TheAmateurProgrammer Feb 3 '13 at 9:41
I may be wrong but I assume that CocoaUser got confused about the use of +className... in the Class Cluster documentation, and the NSObject instance method -className. In this case this is not really a duplicate. –  Martin R Feb 3 '13 at 10:11
add comment

marked as duplicate by jrturton, H2CO3, Kurt Revis, Jack Lawrence, omz Feb 3 '13 at 10:04


2 Answers

From the docs:


The MonthArray class is declared as:

#import <foundation/foundation.h>
@interface MonthArray : NSArray

+ (id)monthArray;
- (unsigned)count;
- (id)objectAtIndex:(unsigned)index;



The implementation of the MonthArray class looks like this:

#import "MonthArray.h"

@implementation MonthArray

static MonthArray *sharedMonthArray = nil;

+ (id)monthArray
    if (!sharedMonthArray) {
        sharedMonthArray = [[MonthArray alloc] init];
    return sharedMonthArray;

- (unsigned)count
    return 12;

- (id)objectAtIndex:(unsigned)index
    if (index >= [self count])
            [self count] - 1];
        return months[index];



share|improve this answer
I cannot see how "+className" relates to category –  Bryan Chen Feb 3 '13 at 9:33
Do you mean something like this + (ClassName *)Instance –  Flexicoder Feb 3 '13 at 9:41
NO, take a look --> developer.apple.com/library/ios/#documentation/general/… –  CocoaUser Feb 3 '13 at 9:43
+ (SGACommon *)sharedInstance, But your class name not "sharedInstance" –  CocoaUser Feb 3 '13 at 9:53
Yep you are right, I wrote that before you clarified with the link to the documentation. I'm assuming the example in the documentation regarding MonthArray isn't helping you understand? –  Flexicoder Feb 3 '13 at 9:56
show 5 more comments

In the Class Cluster documentation that you are referencing, +className... is just a placeholder for the various class methods that are available to create an instance of the class cluster, e.g. numberWithChar, numberWithInt, ... for NSNumber.

This has nothing to do with the -className instance method of NSObject.

share|improve this answer
add comment
