XCode 4.0中的"不完整实现"警告

Bun*_*ori 7 xcode objective-c xcode4

此应用程序是Cococa和Objective C Up and Running一书中的重写代码.

当我在开始时尝试理解所有内容时,我想知道,我在哪里犯了错误,在下面的代码中.对我来说,一切都很好.

因此,您能否帮我确定警告的来源:

Incomplete Implementation
Run Code Online (Sandbox Code Playgroud)

@implementation PhotoPhoto.m源代码文件中得到了这个?

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
Run Code Online (Sandbox Code Playgroud)

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 autorelease];
    caption = [input retain];
}


- (void) setPhotographer: (NSString *)input {
    [photographer autorelease];
    photographer = [input retain];
}


- (void)dealloc
{
    [self setCaption:nil];
    [self setPhotographer:nil];

    [super dealloc];
}

@end
Run Code Online (Sandbox Code Playgroud)

我使用Snow Leopard 10.6.7和Xcode 4.0.0.

Jes*_*her 8

除非是拼写错误,否则您的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
Run Code Online (Sandbox Code Playgroud)

在.m文件中:

@implementation Photo
@synthesize caption, photographer;

    //Other stuff (init and any custom methods for class etc.. NOT getters and setters for variables)
    - (void)dealloc
    {
        [caption release];
        [photographer release];

        [super dealloc];
    }
Run Code Online (Sandbox Code Playgroud)