Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 524
Bunkai.Satori Avatar asked Jun 14 '11 20:06

Bunkai.Satori


3 Answers

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];
    }
like image 57
Jesse Naugher Avatar answered Sep 21 '22 12:09

Jesse Naugher


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];
}
like image 24
FreeAsInBeer Avatar answered Sep 22 '22 12:09

FreeAsInBeer


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.

like image 33
Chris Conover Avatar answered Sep 19 '22 12:09

Chris Conover