- (NSDictionary *)myPropertyList //Calling getter of myPropertyList
{
if(!_myPropertyList){
NSArray *colorsUsed = [[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor blueColor], nil];
_myPropertyList=[[NSDictionary alloc] initWithObjectsAndKeys: colorsUsed, @"colorUsed",[NSNumber numberWithDouble:MAX_RADIUS],@"maximumRadius",[NSNumber numberWithDouble:MIN_RADIUS],@"minimumRadius", [NSNumber numberWithInt:20],@"circleNumbers", nil];;
}
return _myPropertyList;
}
- (NSArray *)generateCircleList
{
int minRadius=[[self.myPropertyList objectForKey:@"minimumRadius"] intValue];
int maxRadius=[[self.myPropertyList objectForKey:@"maximumRadius"] intValue];
...
//code continues
我的模型中有这段代码。当调用使用myPropertyList的函数generateCircleLlist时,它会因EXC_BAD_ACCESS错误而崩溃。我真的环顾四周,但无法找到解决方案。有什么帮助吗?
答案 0 :(得分:0)
您正在创建colorsUsed但使用colorUsed,还添加[colorsUsed release];用于内存管理。
if(!_myPropertyList){
NSArray *colorsUsed = [[NSArray alloc] initWithObjects:[UIColor redColor], [UIColor blueColor], nil];
_myPropertyList=[[NSDictionary alloc] initWithObjectsAndKeys: colorsUsed, @"colorUsed",[NSNumber numberWithDouble:MAX_RADIUS],@"maximumRadius",[NSNumber numberWithDouble:MIN_RADIUS],@"minimumRadius", [NSNumber numberWithInt:20],@"circleNumbers", nil];
[colorsUsed release];
}