How do I create a category in Xcode 6 or higher?
They didn't forget. They just moved it without telling anyone.
Click
File
->New
->File
Select
Objective-C file
underSources
iniOS
orMac OS
respectively and Click NextNow under
File Type:
choose eitherCategory
,Protocol
, orExtension
PS. Under File Name:
whatever you type here will be either the Category
, Protocol
, or Extension
Name.
To create CategoryBaseClass+CategoryName.m/.h:
- File → New → File... or use ⌘N.
- Select Objective-C File.
- Type in category name, select File Type: Category, and then select the base class.
- Complete the flow to create the category.
Here's a visual demonstration:
Xcode6-Beta5 update
The interface has now changed and it's possible to add a Category directly from the New > File window.
See unmircea's answer.
I was surprised myself, and I guess because of Swift they forgot about good old Objective-C.
You have two options:
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.