This is currently what I have for my init,
- (id)init
{
self = [super init];
if (self) {
self.url = [[NSURL alloc] init];
self.blurb = [[NSString alloc] init];
self.author = [[NSString alloc] init];
}
return self;
}
It does nothing, but I have another method called initWithObject: that will use its argument to fill up the instance variables url, blurb, and author. I don't know what I should be doing with this init. Should I throw an exception? What other options do I have?
If you want to override your standard
-initmethod you could either returnnil(if you do not want-initto be used) or do:If you want to stop the use of
-initcompletely you can tag it as an unavailable attribute or use NSAssert:You can use either
UNAVAILABLE_ATTRIBUTEorNSAssert(), but if you useUNAVAILABLE_ATTRIBUTEyou need some kind of implementation of-init, even if it just returnsnil.