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)
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.
create path as follows:
~/Library/Developer/Xcode/Templates/File Templates/Source/My Awesome
Template.xctemplate
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File
Templates/Source/Cocoa Touch Class.xctemplate
TemplateIcon.png
, TemplateIcon@2x.png
and
TemplateInfo.plist
to our My Awesome Template.xctemplate
folder. You can omit copying icons if you do not need them in browser or use your own.NSObjectObjective-C and NSObjectSwift
folders to be able to create both Obj C and Swift files.___FILEBASENAME___.h
, ___FILEBASENAME___.m
, ___FILEBASENAME___.swift
, for example put your macros or in our case delete surrounding NS_ASSUME_NONNULL*
macros