Categories in Objective-C aren't working

前端 未结 5 950
时光说笑
时光说笑 2020-12-16 18:51

I\'m developing an iOS application that needs to deploy to iOS 3.1.3. I need to extend some of the functionality of the NSData class and am using the following code inside N

5条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 19:23

    There is a great post on The Carbon Emitter about about handling categories in iOS. It details an easy way to handle importing categories to your project.

    Make a file containing all of your category imports, in this example it is Extensions.h:

    #import "NSDate+Formatting.h"
    #import "UIFonts+MyFonts.h"
    #import "UIViewController+Tourbot.h"
    

    Add import your file in AppName-Prefix.pch:

    #import 
    
    #ifndef __IPHONE_3_0
    #warning "This project uses features only available in iPhone SDK 3.0 and later."
    #endif
    
    #ifdef __OBJC__
    #import 
    #import 
    #import 
    #import 
    #import "Extensions.h" // Add import here
    #endif
    

提交回复
热议问题