wj2061 wj2061 - 3 months ago 18
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

fatalError
in Swift:

class subClass:NSObject{
private var k:String!

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

init(kk:String){
k = kk
}
}


How can I do it in Objective-C?

Answer

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")