In an abstract class, a custom init method looks like this:
- (id)init
{
self = [super init];
if (self)
{
//do some initialisations
}
return self;
}
This would work perfectly fine when working with abstract classes: no problems at all. However, when creating objects, I prefer Class *object = [Class new]; over Class *object = [[Class alloc]init];. The problem with such a method in my abstract class, is that this doesn't work:
+ (id)new
{
id object = [super new];
if (object)
{
//do some initialisations
}
return object;
}
When trying to access properties of the object, Xcode will bring up an error, saying the corresponding property is not found on object of type '__strong id'. I'm guessing that's because the compiler has no idea what properties my object has, as it's just been created.
Is there any way to get around this limitation? If there's not, I'll just use the init method as it works just fine, but I was just curious about this.