wj2061 wj2061 - 9 months ago 67
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?


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