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

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


You can raise an exception in this case. Something like this:

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


NSAssert(NO, @"balabala");

or

- (instancetype)init NS_UNAVAILABLE;

========== Update ==========

Thanks to @Cœur

NSAssert is disabled by default in production, which is different with FatalError. NSException is better.

enter image description here


Best practice is to declare in the .h:

(instancetype)init __attribute__((unavailable("init() is unavailable")));

Then the compiler won't compile if anyone calls it.