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

后端 未结 8 1823
太阳男子
太阳男子 2020-11-27 09:53

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 the

8条回答
  •  醉酒成梦
    2020-11-27 10:04

    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) named UIImage+Additions(ClassName+CategoryName) and override its interface and implementation some thing like

    UIImage+Additions.h

    #import 
    
    @interface UIImage(Additions)
    
    +(void)testMethod;
    
    @end 
    

    UIImage+Additions.m

    #import "UIImage+Additions.h"
    
    @implementation UIImage (Additions)
    
    +(void)testMethod
    {
    
    }
    
    @end
    

    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

提交回复
热议问题