属性'shapeMatched'的类型与访问者'setShapeMatched:'的类型不匹配

时间:2011-11-23 12:48:17

标签: iphone objective-c ios

我正在开发一个iPhone 4应用程序,我在课堂上遇到了问题:

    @interface Pattern : NSObject {

        int maxNumShapes;
        NSMutableArray* shapes;
        NSMutableArray* shapeMatched;
        CGSize bounds;
    }
    @property (nonatomic, retain, readonly) NSMutableArray* shapes;
    @property (nonatomic, retain, readonly) NSMutableArray* shapeMatched;

    ...
    - (void) setShapeMatched:(ShapeType)type;

@end

及其实施:

- (void) setShapeMatched:(ShapeType)type {
    int index = 0;
    if (shapes != nil)
    {
        for(Object2D* obj in shapes)
        {
            if (obj.figure == type)
            {
                [shapeMatched replaceObjectAtIndex:index 
                                        withObject:[NSNumber numberWithBool:YES]];
                obj.withFillColor = YES;
                break;
            }
            else
                index++;
        }
    }
}

我收到以下警告:

Type of property 'shapeMatched' does not match type of accessor 'setShapeMatched:'

如何修复此警告?

2 个答案:

答案 0 :(得分:14)

您的方法- (void)setShapeMatched:(ShapeType)type可能旨在更改shapeMatched数组中的某些内容,但是,它的名称会覆盖该属性的setter以用于该相同的数组。

目前还不清楚,但如果你真的想要覆盖setter,那么参数必须是NSMutableArray *类型,因为那是你属性的类型。否则,如果您只是执行其他操作,请将其重命名以避免冲突。 setShapeMatchedType:(ShapeType)t可能是个不错的选择。

答案 1 :(得分:6)

您需要将自定义setShapeMatched:重命名为其他内容(例如setMyShapeMatched)。 setShapeMatched:已被用作已声明属性的setter。