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
-init
method you could either returnnil
(if you do not want-init
to be used) or do:If you want to stop the use of
-init
completely you can tag it as an unavailable attribute or use NSAssert:You can use either
UNAVAILABLE_ATTRIBUTE
orNSAssert()
, but if you useUNAVAILABLE_ATTRIBUTE
you need some kind of implementation of-init
, even if it just returnsnil
.