Search code examples
iosobjective-cnullable

nonnull value as return value in method doesn't work?


I thought that if I specified nonnull attribute for the return value in method, and try to return nil/null - app will crash, but I see that app didn't crashed, it successful returned null. It's expected behaviour (Nullability is just for compatibility with Swift, and no real help for ObjC code, or I'm doing something wrong? My method declaration that returning me null:

- (nonnull PFObject *)getParseObjFromManagObj:(nonnull NSManagedObject *)managObj;

Solution

  • Nullablity is just a hint for the compiler. It should flag your code with a warning if you try to return a null/nil, but it does not generate any runtime code.

    Swift uses these tags to tell if the method returns an optional or not.