objective-cxcodeheader-filesxcode10objective-c-nullability

Prevent Xcode from creating NS_ASSUME_NONNULL_BEGIN and NS_ASSUME_NONNULL_END on new headers


I've updated Xcode and since updating I've been getting NS_ASSUME_NONNULL_BEGIN and NS_ASSUME_NONNULL_END macros around every new header file for every new class that I create.

I know what it does, but I'm not interested in nullability annotations it and it causes unnecessary warnings when I try to set some properties to nil in my app (which are perfectly okay to set to nil).

How do I prevent Xcode from creating these every time I create a new file? (other than the obvious: deleting them individually)


Solution

  • Based on this and this arcticles I was able to create custom template to get rid of NS_ASSUME_NONNULL* macros.

    Excerpt from the first arcticle:

    Location

    These user-defined templates are located in ~/Library/Developer/Xcode/Templates/File Template. If such folder is missing you can create it yourself and Xcode will be linked to it upon reopening. Also you can group them into subfolders inside that folder. For example, ~/Library/Developer/Xcode/Templates/File Template/Custom Templates and Xcode will render those groups properly when creating a new file.

    Template Setup

    Each template is a folder with .xctemplate extension. That folder contains file templates and resources that will be populated and added to a project and configuration TemplateInfo.plist.

    All template settings and fields that user can fill in during template creation are defined in TemplateInfo.plist.