swift - Objective-C Nullability: Qualifying Constant Strings -


i have gotten pretty habit of declaring , using constant strings things nsnotification names. declare them so:

extern nsstring * const abcawesomethinghappenednotification; 

with introduction of xcode 6.3 , swift 1.2, i'm going , auditing objective-c classes interop swift using new nonnull, nullable, , null_unspecified qualifiers.

when adding qualifiers header has externally visible static strings, receive following warning:

warning: pointer missing nullability type specifier (__nonnull or __nullable)

hmm. that's confusing / interesting. can explain reasoning behind message? when using abcawesomethinghappenednotification in swift, never suggests it's optional string or implicitly unwrapped string.

in implementation, define:

nsstring * const abcawesomethinghappenednotification = @"abcawesomethinghappenednotification"; 

in case pointer nonnull. however, valid:

nsstring * const abcawesomethinghappenednotification = nil; 

which must considered nullable because pointer null pointer.

(the explicit initialisation nil redundant since happens implicitly if no initial value provided, clarifies example.)


Comments

Popular posts from this blog

Java 8 + Maven Javadoc plugin: Error fetching URL -

css - SVG using textPath a symbol not rendering in Firefox -

order - Notification for user in user account opencart -