objective-c – XCode 4.0中的“不完整实现”警告
发布时间:2020-12-14 19:54:55 所属栏目:百科 来源:网络整理
导读:此应用程序是来自 Cococa and Objective C Up and Running书籍的重写代码. 当我试着在开始时理解一切时,我想知道,我在哪里犯了错误,在下面的代码中.对我来说,一切都很好. 因此,您能否帮我确定警告的来源: Incomplete Implementation 我在Photo.m源代码文件
此应用程序是来自
Cococa and Objective C Up and Running书籍的重写代码.
当我试着在开始时理解一切时,我想知道,我在哪里犯了错误,在下面的代码中.对我来说,一切都很好. 因此,您能否帮我确定警告的来源: Incomplete Implementation 我在Photo.m源代码文件中的@implementation Photo行中得到了这个? Photo.h #import <Foundation/Foundation.h> @interface Photo : NSObject{ NSString* caption; NSString* photographer; } + (Photo*) photo; - (NSString*) caption; - (NSString*) photographer; - (void) setCaption: (NSString*)input; - (void) setPhotographer: (NSString*)input; @end Photo.m #import "Photo.h" @implementation Photo // <- Incomplete Implementation? - (id)init { self = [super init]; if (self) { [self setCaption:@"Default Caption"]; [self setPhotographer:@"Default Photographer"]; } return self; } + (Photo*) caption { Photo* newPhoto = [[Photo alloc] init]; return [newPhoto autorelease]; } - (NSString*) caption { return caption; } - (NSString*) photographer { return photographer; } - (void) setCaption:(NSString *)input { ; caption = [input retain]; } - (void) setPhotographer: (NSString *)input { [photographer autorelease]; photographer = [input retain]; } - (void)dealloc { [self setCaption:nil]; [self setPhotographer:nil]; [super dealloc]; } @end 我使用Snow Leopard 10.6.7和Xcode 4.0.0. 解决方法
除非是拼写错误,否则你的Class方法定义为(Photo *)Photo;没有实现(有一个(Photo *)Caption {}方法看起来只是一个意外.
编辑:一个更简单的方法是使用属性,这是一个为我们创建变量的getter和setter的快捷方式(请参阅此链接以获得一个好的初学者教程:iPhone 101),如下所示: 在你的.h文件中: @interface Photo : NSObject{ NSString* caption; NSString* photographer; } @property (nonatomic,retain) NSString *caption; @property (nonatomic,retain) NSString *photographer; @end 在.m文件中: @implementation Photo @synthesize caption,photographer; //Other stuff (init and any custom methods for class etc.. NOT getters and setters for variables) - (void)dealloc { ; [photographer release]; [super dealloc]; } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |