Search code examples
objective-cxcodexcode4

"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 {
    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

I use Snow Leopard 10.6.7 and Xcode 4.0.0.


Solution

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