Does someone knows how to make this kind of "class auto instantiator":
myDict = [NSDictionnary dictionnaryWithCapacity: 0];
I can't find any resource on this (maybe I just don't know the terminology)
Does someone knows how to make this kind of "class auto instantiator":
myDict = [NSDictionnary dictionnaryWithCapacity: 0];
I can't find any resource on this (maybe I just don't know the terminology)
Not sure what you mean... Do you mean a class method to create an object?
@implementation myClass
+(myClass *)myClassWithParameter:(int)whatever
{
myClass instance = [[myClass alloc] init];
[instance doWhatever:whatever];
return instance;
}
It's a class method (denoted by "+" instead of "-").
+ (MyClass *)myClassWithObject:(ObjectType *)object
{
//do whatever you need to make an instance of MyClass using that object's data
return myClassInstance;
}
That's just a static method which you can use in place of alloc/init. In objective-c, static method are called on an instance of the meta-class which is why they are sometimes called "Class methods".
@implementation TheBestObjectEver
+ (instancetype)makeMeAnObject {
return [[self alloc] init];
}
@end
TheBestObjectEver *myObject = [TheBestObjectEver makeMeAnObject];