Reputation: 3285
I recently downloaded Xcode 9.2 and updated my project settings to recommended. Now I'm getting this warning in my code for all the places where I've used assert for eg:
assert(@"Must be implemented by subclass");
What is the proper alternative for this?
Upvotes: 0
Views: 1739
Reputation: 50089
a) assert needs a condition to check. you treat the string as a condition and it is non-null... do
b) you use a NSString and not a char* so you pass objC object to C which wont work in this case either ... do
assert(codition & "Message");
c) you should use NSAssert for ObjC Code .. do
NSAssert(codition, @"Message");
Upvotes: 0
Reputation: 42588
If you are using Objective-C, you want to call NSAssert()
, not assert()
(which is a C function).
NSAssert(NO, @"Must be implemented by subclass");
If you want to continue using assert()
, you should treat it like a C function.
assert(0); // <-- Note: no message is provided
You might get away with
assert(/* Must be implemented by subclass */ 0);
or
assert("Must be implemented by subclass" == NULL); // <-- Note: No `@`
Upvotes: 2
Reputation: 8501
Your assert
condition is a string which will always pass the test.
You should be checking a condition in the assert
Upvotes: 1