Objective-C 错误消息:发现名为“setBounds:”的多个方法的结果、参数类型或属性不匹配

Objective-C error message: Multiple methods named 'setBounds:' found with mismatched result, parameter type or attributes

提问人:Phone Htet Aung 提问时间:11/5/2023 最后编辑:Phone Htet Aung 更新时间:11/7/2023 访问量:39

问:

@implementation Circle

- (void) setFillColor: (ShapeColor) c
{
  fillColor = c;
}

- (void) setBounds: (ShapeRect) b
{
    bounds = b;
}

- (void) draw
{
    NSLog (@"drawing a circle at (%d %d %d %d) in %@",
        bounds.x, bounds.y,
        bounds.width, bounds.height,
        colorName(fillColor));
}

@end // Circle

void drawShapes (id shapes[], int count)
{
    int i;
    for (i = 0; i < count; i++) {
        id shape = shapes[i];
        [shape draw];
    }
}

int main (int argc, const char * argv[])
{
  id shapes[1];
  ShapeRect rect0 = { 0, 0, 10, 30 };
  shapes[0] = [Circle new];
  [shapes[0] setBounds: rect0];
  [shapes[0] setFillColor: kRedColor];
  drawShapes (shapes, 1);
  return (0);
}

我从名为“在 mac 上学习 Objective-C”的书中编写了这个代码块,我从标题中收到了错误消息,并且此错误“将'__strong id *'传递给类型为'__unsafe_unretained id *'的参数会更改指针的保留/释放属性”

作为警告,我得到了这个“计算结果为零的表达式,被视为类型为'CGColorRef _Nullable'(又名'struct CGColor *')的空指针常量”

我想知道我该如何解决这个问题。 这是“@interface”

@interface Circle : NSObject
{
    
    ShapeColor  fillColor;
    ShapeRect   bounds;
    
}
- (void) setFillColor: (ShapeColor) fillColor;
- (void) setBounds: (ShapeRect) bounds;
- (void) draw;

@end // Circle

Objective-C Xcode

评论

0赞 Willeke 11/7/2023
这本书有点旧了。如果在构建设置中关闭“Objective-C 自动引用计数”,则错误将消失。
0赞 Phone Htet Aung 11/10/2023
你推荐任何关于Objective-C的书吗?

答: 暂无答案