objective-c - Xcode 无法识别自定义类方法

标签 objective-c cocoa cocoa-touch xcode

我编写了以下自定义类:

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/

相关文章:

ios - 换行后如何在 UITextView 中获取行?

ios - NSData到UIImage的质量

iphone - NSLog(@"%@", super )崩溃

iphone - 如何使用 ABPeoplePicker 隐藏一些属性

objective-c - 如何在osx中​​创建静态库

IOS:如何在循环内使用 UIAlertView

iphone - 使 UIImagePickerController (相机 View )仅显示一定数量的像素

objective-c - OS X 计数按下的键没有访问权限

cocoa - 将 NSWindow 显示为工作表的正确方法

macos - 查找当前填充和描边颜色空间形式CGContext中的组件数量?