Cocoa Design Patterns
Learning OpenGL ES for iOS
Presentations
Buy at Amazon Now
  • Cocoa Design Patterns
    Cocoa Design Patterns
    by Erik M. Buck, Donald A. Yacktman
  • Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    Learning OpenGL ES for iOS: A Hands-on Guide to Modern 3D Graphics Programming
    by Erik M. Buck

Errata > Chapter 25 : Class Clusters

I have some questions about apple's class cluster document.

header
---------------------------------------------------------------------------------------------------------
#import <foundation/foundation.h>
@interface MonthArray : NSArray
{
}

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

@end


implementation
---------------------------------------
#import "MonthArray.h"

@implementation MonthArray

static MonthArray *sharedMonthArray = nil;
static NSString *months[] = { @"January", @"February", @"March",
@"April", @"May", @"June", @"July", @"August", @"September",
@"October", @"November", @"December" };

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

- (unsigned)count
{
return 12;
}

- objectAtIndex:(unsigned)index
{
if (index >= [self count])
[NSException raise:NSRangeException format:@"***%s: index
(%d) beyond bounds (%d)", sel_getName(_cmd), index,
[self count] - 1];
else
return months[index];
}

@end
---------------------------------------------------------------------------------------------------------

Q1 : What does the mean "+ monthArray" in Objective-C?
Q2 : Does the "+ monthArray" is equal to "+ (id)monthArray"?

Thanks a lot.
February 3, 2013 | Unregistered CommenterDiuming
Sorry, It's not error. It's my question
February 3, 2013 | Unregistered CommenterDiuming
Yes, "+ monthArray" is equal to "+ (id)monthArray". The "id" type is the default return type for Objective-C methods.
February 3, 2013 | Registered CommenterErik Buck
Hi Erik Buck,
Thanks a lot.
February 3, 2013 | Unregistered CommenterDiuming