当函数使用 getter 时 Objective C 中的 EXC_BAD_EXCESS
- (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 错误而崩溃。我确实环顾四周,但找不到解决方案。有什么帮助吗?
- (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
I have this piece of code in my model. When the function generateCircleLlist is called that uses the myPropertyList, it is crashing with a EXC_BAD_ACCESS error. I really looked around but couldn't find a solution to this. Any help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在创建 colorUsed 但使用 colorUsed,还要添加 [colorsUsed release];用于内存管理。
You are creating colorsUsed but using colorUsed, also add [colorsUsed release]; for memory management.