我编写了以下自定义类:
AKRelativeDates.h
#import <Foundation/Foundation.h>
#import "NSDate-Utilities.h"
@interface AKRelativeDates
- (NSString *)relativeDateFromDate:(NSDate *)date in24hFormat:(BOOL)in24hFormat capitalized:(BOOL)capitalized;
@end
AKRelativeDates.m
#import "AKRelativeDates.h"
@implementation AKRelativeDates
- (NSString *)relativeDateFromDate:(NSDate *)date in24hFormat:(BOOL)in24hFormat capitalized:(BOOL)capitalized
{
// method implementation removed
return @"test";
}
@end
我导入了头文件,类被识别,但方法不能。我做错了什么吗?
最佳答案
您的 header 中遗漏了一些内容:
#import <Foundation/Foundation.h>
#import "NSDate-Utilities.h"
@interface AKRelativeDates : NSObject //Follow the class name with the superclass.
{
//Now enclose any class objects if any - if none then brackets are optional
}
//And now time for the method declarations:
- (NSString *)relativeDateFromDate:(NSDate *)date in24hFormat:(BOOL)in24hFormat capitalized:(BOOL)capitalized;
@end
此外,如果它是一个类方法(即您不想在使用此方法之前创建对象),则将“-”替换为“+”
关于objective-c - Xcode 无法识别自定义类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5593707/