There seem to be two questions here:
How to ensure that the value created in my singleton sharedInstance method and returned by this method is actually non-zero at runtime?
How can I satisfy the system with null sequence annotations, compiler warnings, and Swift bridge that I return a nonnull pointer?
Enforcement / Enforcement nonnull
At some point, every API contract comes down to a human contract. The compiler can guarantee that, for example, you cannot take the result of a nullable call and return it from a method whose return type is nonnull ... but somewhere there is usually an original call whose return type is nonnull simply because the programmer wrote it said: "I promise never to return zero, cross my heart, etc."
If you are familiar with Swift, this is similar to the situation with Implicitly Unwrapped Optionals - you use them when you know that the value cannot be nil, but cannot prove this knowledge to the compiler, because this knowledge is external to the source code (for example , something from the resource of the storyboard or package).
Here is the situation - you βknowβ that init will never return zero because you wrote / received the source for the initializer in question, or because it is just NSObject init , which is documented on return self without doing anything. The only situation where the call to this initializer fails is that the previous alloc call failed (and therefore you call the method on nil , which always returns nil ). If alloc returns nil, you are already in terrible situations , and your process is not too long for this world - this is not a case of failure for developing the API around.
(Annotations for Nullability usually describe the intended use of the API, rather than the more extreme edge and corner cases. If the API call fails due to a universal error , it does not make sense to annotate it as nullable, similarly if the API fails only at the input, which can be excluded from annotations of nonzero parameters, the return value can be considered nonzero.)
So a long story: yes, just put NS_ASSUME_NONNULL around your header and send your implementation of sharedInstance as it is.
Return nonnull with a null value
This is not so, but suppose you have a value that is annotated as nullable , but you know (or "know") that it can never be zero and wants to return it from your nonnull named method, and you are in situations where you get a compiler warning to try.
There is a syntax: just enter the value into the expected return type, annotations, and that's it:
return (NSWhatever *_Nonnull)whatever;
In your case, this is not required - since you are dealing with special types id and instancetype , the compiler is more forgiving about the conversion of zero probability and probably will not warn you to start with.