Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a category in Xcode 6 or higher?

I want to create a category on UIColor in my app using Xcode 6. But the thing is that in Xcode 6 there is no Objective-C category file template.

Is there any option to create a category in Xcode 6?

like image 510
Yalamandarao Avatar asked Jun 20 '14 09:06

Yalamandarao


People also ask

How to create category in XCode?

Open your XCode project, click on File -> New -> File and choose Objective-C file , click Next enter your category name say "CustomFont" choose file type as Category and Class as UIFont then Click "Next" followed by "Create."

What are IOS categories?

You use categories to define additional methods of an existing class—even one whose source code is unavailable to you—without subclassing. You typically use a category to add methods to an existing class, such as one defined in the Cocoa frameworks.


2 Answers

They didn't forget. They just moved it without telling anyone.

  1. Click File -> New -> File

  2. Select Objective-C file under Sources in iOS or Mac OS respectively and Click Next

  3. Now under File Type: choose either Category, Protocol, or Extension

PS. Under File Name: whatever you type here will be either the Category, Protocol, or Extension Name.

like image 173
unom Avatar answered Nov 15 '22 22:11

unom


To create CategoryBaseClass+CategoryName.m/.h:

  1. File → New → File... or use ⌘N.
  2. Select Objective-C File.

enter image description here

  1. Type in category name, select File Type: Category, and then select the base class.

enter image description here

  1. Complete the flow to create the category.
like image 26
Zorayr Avatar answered Nov 15 '22 22:11

Zorayr