user5412293
user5412293

Reputation:

NS_ASSUME_NONNULL_BEGIN Macro

I am following an online tutorial from team tree house and one of the steps is to create an NSManagedObject subclass for my data model.

When I did that the code automatically generated a class and set of macros at the beginning and and the end:

NS_ASSUME_NONNULL_BEGIN

NS_ASSUME_NONNULL_END

I was searching online but I could not find any documentation about what these guys are doing here. By the way they were defined in the header NSObjCRuntime.h

Any ideas what purpose they serve?

Upvotes: 64

Views: 36894

Answers (1)

DDP
DDP

Reputation: 2563

It's a convenience macro to save you typing nonnull in your headers. From the Swift blog detailing how new safety features have been incorporated back in Objective-C:

To ease adoption of the new annotations, you can mark certain regions of your Objective-C header files as audited for nullability. Within these regions, any simple pointer type will be assumed to be nonnull.

See Nullability and Objective-C - https://developer.apple.com/swift/blog/?id=25

Upvotes: 88

Related Questions