wj2061 wj2061 - 1 year ago 108
Objective-C Question

Is there an Objective-C equivalent to Swift's fatalError?

I want to discard superclass's default init method.I can achieve this easily with

in Swift:

class subClass:NSObject{
private var k:String!

override init(){
fatalError("init() has not been implemented")

k = kk

How can I do it in Objective-C?

Answer Source

You can raise an exception in this case:

Something like this. Refer this

  [NSException raise:@"InitNotImplemented" format:@"Subclasses must implement a valid init method"];

Or also you can even use assert statement.

assert(false, "Subclasses must implement init")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download