views:

87

answers:

2

I want a class that take a REQUIRED argument like the UITableViewController that does not have init.

Currently I just throw an exception when invoking init.

Is there a way to deactivate it completely?

A: 

No. Just redefine it to some error condition. This is bad style anyway and I question your motives.

jer
Well the motive is that i think it was good style if it was possible since the object have little meaning if not well initialized. Why do you think it's bad style?
gurghet
Well in fact you can call `[[UITableViewController alloc] init]`. It does have `init`, because it's a subclass of `NSObject`. I understand your motivation but it's just not a standard practice in Objective-C to try to remove/hide methods.
Yuji
I see, I'll initialize it with some random default argument. Thank you guys you're amazing.
gurghet
Well, it's not a standard practice either. What people usually do is just not defining the `init` method in your subclass.
Yuji
Let me add: not defining `init` in your class does not remove the `init` method. What happens when you call `[[YourClass alloc] init]` in that case is that it calls the superclass's `init`, which will be `NSObject`'s `init`. Which will zero-out all the ivars.
Yuji
I don't see why this is bad style. If i have a class that requires another object to be created I would rather an error be thrown if I call the wrong init method than being left with bad data.
skorulis
i have just declared bad data to be logical dummy data so i can catch the error down the stack
gurghet
@gurghet - You might want to read up on designated initializers, as well: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjectiveC/Articles/ocAllocInit.html#//apple_ref/doc/uid/TP30001163-CH22-106376 Also, a song on the topic can't hurt: http://www.youtube.com/watch?v=ajlESsRXqmM
Brad Larson
A: 

A non-existant method (anywhere in the class hierarchy) for any object would cause the runtime to throw an exception. If that's what you mean by a deactivated method, and you're throwing an exception already, then you're already done.

hotpaw2