OCMock目前不支持的原始參數寬鬆匹配。然而,我有我需要上OCMockObject
設置屬性,這個屬性被聲明爲copy
屬性。因此它實現了- (id)copyWithZone:(NSZone *)zone
。 NSZone
被定義爲typedef struct _NSZone NSZone
,並且因爲它是一個結構,它是一個原始類型。因此,我得到的錯誤我該如何模擬一個NSZone?
Incompatible pointer types sending 'id' to parameter of type 'NSZone *' (aka 'struct _NSZone *')
在這條線:
[[mockObject expect] copyWithZone:[OCMArg any]];
是解決它的最好方法聲明屬性與retain
屬性,而不是copy
?使用copy
的好處是該對象不可能被另一個對象修改。