Search code examples
iosobjective-cios-frameworks

Objective-C: enforce compile error upon nullability annotation violation


Background

We have been developing public dynamic iOS / macOS framework. The framework is written in Objective-C, but it has full compatibility with Swift.

Recently, we have changed nullability annotation for one of our public API methods:

from

- (void)setServer:(nullable ABCLocation *)location;

to

- (void)setServer:(nonnull ABCLocation *)location;

, so developer would need to create [ABCLocation default] instance and pass it to new API.

Question

Now, we are concerned, how to enforce / notify developers to change their existed code around our new API?

When using the API with Swift, it seems to handle nullability pretty well by throwing an error.

Objective-C, though, generates a warning only when nil is passed, Xcode does nothing, when developers passes a nullable property to the method.

How do we enforce developers to change their API? What are the common practices here?

UPD:

We distribute the framework as a binary, built with Release configuration, where assertions are turned off.

UPD #2:

So far, we have accepted the reality when our API is used from Objective-C. However, we have implemented a "fail safe" behavior: if nil is passed, the method internally creates [ABCLocation default] instance and passes it through implicitly.


Solution

  • Generating a warning when annotation is not met is a good practice. Making changes like nullable -> nonnull in APIs is not.