我想用Xcode 6在我的应用程序中创建一个UIColor类别。但问题是,在Xcode 6中没有Objective-C分类文件模板。

在Xcode 6中有创建类别的选项吗?


当前回答

你可以从旧版本的Xcode中复制你想要的模板,我为此做了一个shell脚本:https://github.com/cDigger/AddMissingTemplates

其他回答

你可以从旧版本的Xcode中复制你想要的模板,我为此做了一个shell脚本:https://github.com/cDigger/AddMissingTemplates

下面是一个视觉演示:

他们没有忘记。他们没告诉任何人就把它搬走了。

单击“文件->新建->文件” 在iOS或Mac OS下分别选择“Sources”下的“Objective-C”文件,单击“Next” 现在在文件类型下:选择类别,协议或扩展

PS.在文件名称下:无论你在这里输入什么,都将是类别,协议或扩展名。

Xcode6-Beta5更新

界面现在已经改变,可以直接从新建>文件窗口添加一个类别。

请看unmircea的回答。


我自己也很惊讶,我猜是因为Swift,他们忘记了好的老Objective-C。

你有两个选择:

Create an Objective-C class with the category name, example UIView+Powerups, then manually change the interface to match the one of category. Note that the snippet for the category interface and implementation is still working, so that's extra easy: type @interface-category and @implementation-category. Import it from Xcode 5! Use this command: cp -r /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File\ Templates/Cocoa\ Touch/Objective-C\ category.xctemplate /Applications/Xcode6-Beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Xcode/Templates/File\ Templates/Source/ Close and reopen Xcode 6 and you'll find "Objective-C Category" in the wizard for the new file.

创建CategoryBaseClass+CategoryName.m/.h:

文件→新建→文件…或使用⌘N。 选择Objective-C File。

输入类别名称,选择文件类型:类别,然后选择基类。

完成流以创建类别。