我正在從一本書中得到一個例子,它似乎並沒有工作我收到警告不完整的實現。當我運行該程序時,出現錯誤信息「EXC_BAD_ACCESS」。該警告在行return [NSString stringWithFormat:@"Name:...
的.m文件中有沒有人知道我在做什麼錯了?不完整的實現示例幫助!
我.m文件
#import "RadioStation.h"
@implementation RadioStation
+ (double)minAMFrequency {
return 520.0;
}
+ (double)maxAMFrequency {
return 1610.0;
}
+ (double)minFMFrequency {
return 88.3;
}
+ (double)maxFMFrequency {
return 107.9;
}
- (id)initWithName:(NSString *)newName atFrequency:(double)newFreq atBand:(char)newBand {
self = [super init];
if (self != nil) {
name = [newName retain];
frequency = newFreq;
band = newBand;
}
return self;
}
- (NSString *)description {
return [NSString stringWithFormat:@"Name: %@, Frequency: %.1f Band: %@", name, frequency, band];
}
- (void)dealloc {
[name release];
[super dealloc];
}
@end
我.h文件中
radiosimulation.m文件:
int main (int argc, const char * argv[]) {
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
// insert code here...
NSMutableDictionary* stations = [[NSMutableDictionary alloc] init];
RadioStation* newStation;
newStation = [[RadioStation alloc] initWithName:@"Star 94"
atFrequency:94.1
atBand:'F'];
[stations setObject:newStation forKey:@"WSTR"];
[newStation release];
NSLog(@"%@", [stations objectForKey:@"WSTR"]);
newStation = [[RadioStation alloc] initWithName:@"Rocky 99"
atFrequency:94.1
atBand:'F'];
[stations setObject:newStation forKey:@"WKFR"];
[newStation release];
NSLog(@"%@", [stations objectForKey:@"WKFR"]);
[stations release];
[pool drain];
return 0;
調試器中的堆棧跟蹤會告訴你你在哪裏得到'EXC_BAD_ACCESS'。如果您在此處發佈堆棧跟蹤,我們將能夠提供更多幫助。 – highlycaffeinated
你在哪一行得到警告? – taskinoor
@highlycaffeinated如何訪問堆棧跟蹤> – iPhoneDev85