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?
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?
Here's a visual demonstration:
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 theCategory
,Protocol
, orExtension
Name.There is no predefined template to create category in Xcode 6 beta(for time being),they may add this option later. As a work around you can create a
Cocoa Touch Class
(its not proper i know but no other way) namedUIImage+Additions
(ClassName+CategoryName) and override its interface and implementation some thing likeUIImage+Additions.h
UIImage+Additions.m
Edit
This answer was written before finding a way of creating category in the Xcode 6 beta. Check unmircea's answer for the right way of creating category
Extending unmircea's fantastic answer re: how to create a custom category to implement a custom
UIColor
palette, you could create a category.Once you've created your category (in this example, it's a category called
ColorPalette
of classUIColor
), you'll have a header and an implementation file.UIColor+ColorPalette.h
UIColor+ColorPalette.m
To use your custom color palette, just import the header into the class where you'd like to implement your custom colors:
and call the color as you would a standard color like
redColor
,greenColor
, orblueColor
.Here's a link to a slightly more in-depth discussion of creating a custom palette.
Additionally, here is a tool to help you select the custom color values
You can create "extension" file like NSString+Helper:
Done. enjoy coding
You could just copy the templates you want from an older version of Xcode, I made a shell script for this:https://github.com/cDigger/AddMissingTemplates