I’m new to ios programming and stuck in my second tutorial which called Your Second iOS App about bird sighting in developer.apple.com. At the end of the ‘Displaying Information in the Detail Scene’ section when i run the code i get the “no visible @interface for ‘birdsighting’ declares the selector ‘initwithname:location:date:’ ” error in BirdSightingDataController.m file at the “sighting = [[BirdSighting alloc] initWithName:@”Pigeon” location:@”Everywhere” date:today];” line. I checked the document lots of times and did the tut again but couldnt find how to i correct this?
#import "BirdSightingDataController.h"
#import "BirdSighting.h"
@interface BirdSightingDataController ()
- (void)initializeDefaultDataList;
@end
@implementation BirdSightingDataController
- (void)initializeDefaultDataList {
NSMutableArray *sightingList = [[NSMutableArray alloc] init];
self.masterBirdSightingList = sightingList;
BirdSighting *sighting;
NSDate *today = [NSDate date];
sighting = [[BirdSighting alloc] initWithName:@"Pigeon" location:@"Everywhere" date:today];
[self addBirdSightingWithSighting:sighting];
}
- (void)setMasterBirdSightingList:(NSMutableArray *)newList {
if (_masterBirdSightingList != newList) {
_masterBirdSightingList = [newList mutableCopy];
}
}
- (id)init {
if (self = [super init]) {
[self initializeDefaultDataList];
return self;
}
return nil;
}
- (NSUInteger)countOfList {
return [self.masterBirdSightingList count];
}
- (BirdSighting *)objectInListAtIndex:(NSUInteger)theIndex {
return [self.masterBirdSightingList objectAtIndex:theIndex];
}
- (void)addBirdSightingWithSighting:(BirdSighting *)sighting {
[self.masterBirdSightingList addObject:sighting];
}
@end
Birdsighting.h file
#import <Foundation/Foundation.h>
@interface BirdSighting : NSObject
@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *location;
@property (nonatomic, strong) NSDate *date;
-(id)initWithName:(NSString *) name locaiton:(NSString *)location date:(NSDate *) date;
@end
Check Birdsighting.h and make sure that the method
is declared there. This essentially tells other classes what methods are available to instances of the Bidsighting class.
Its possible there is a typo in the interface declaration (this happens even in apple samples).