0

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?

Francis F
  • 3,157
  • 3
  • 41
  • 79

3 Answers3

2

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 `@`
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
1

Your assert condition is a string which will always pass the test.

You should be checking a condition in the assert

Flexicoder
  • 8,251
  • 4
  • 42
  • 56
0

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");
Daij-Djan
  • 49,552
  • 17
  • 113
  • 135