开发者

"Incomplete implementation" warning in XCode 4.0

This application is rewritten code from the Cococa and Objective C Up and Running book.

As I try to understand everything in the beginning, I would like to know, where I made a mistake, in the code below. To me, everything looks fine.

Could you, therefore, help me identify the source of the warning:

Incomplete Implementation

I got this in the @implementation Photo line in Photo.m source code file?

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 {
    P开发者_Python百科hoto* 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

I use Snow Leopard 10.6.7 and Xcode 4.0.0.


Unless its a typo, your Class method defined as + (Photo*) Photo; is not implemented (there is a + (Photo*) Caption {} method which looks its just an accident.

Edit: A simpler way to do have this functionality is to use properties, which are a shortcut that create the getter and setter for a variable for us, (see this link for a good beginner's tutorial: iPhone 101) for your instance variables like so:

in your .h file:

@interface Photo : NSObject{

    NSString* caption;
    NSString* photographer;    
}
@property (nonatomic, retain) NSString *caption;
@property (nonatomic, retain) NSString *photographer;
@end

in your .m file:

@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];
    }


You are receiving this error because in your header file you declared that there would be a method:

+ (Photo*) photo;

but you didn't implement it in the m file.

EDIT:

It looks like this:

+ (Photo*) caption {
    Photo* newPhoto = [[Photo alloc] init];
    return [newPhoto autorelease];
}

should be:

+ (Photo*) photo {
    Photo* newPhoto = [[Photo alloc] init];
    return [newPhoto autorelease];
}


In general, when you mouse over the warning, it will not tell you which method it is missing, but there are at least two other ways to get this information:

  1. Type Cmd-4 or select the Issue Navigator view (the ! in a triangle icon), then expand the "Semantic Issue" warning for this issue. You will then see a message to the effect of "Method definition for "" not found.

  2. Type Cmd-7 or select the Log View (the rightmost icon that looks like a caption bubble), then select the appropriate issue from the list. You will see the same message.


You are missing +photo because you accidentally typed caption:

+ (Photo*) caption {
    Photo* newPhoto = [[Photo alloc] init];
    return [newPhoto autorelease];
}

should be

+ (Photo*) photo {
    Photo* newPhoto = [[Photo alloc] init];
    return [newPhoto autorelease];
}


Your .m file does not have the implementation for:

+ (Photo*) photo;

That's the missing method.


try changing

+ (Photo*) caption {
    Photo* newPhoto = [[Photo alloc] init];
    return [newPhoto autorelease];
 }

to

+ (Photo*) photo {
    Photo* newPhoto = [[Photo alloc] init];
    return [newPhoto autorelease];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜