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.
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:
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With