블록이있는 하위 클래스 개체를 사용하는 방법을 이해하는 데 문제가 있습니다. 다음은 내가 시도하는 것의 예입니다. PFItem은 PFObject의 하위 클래스입니다.fetchIfNeededInBackgroundWithBlock과 같은 블록에서 PFObject의 하위 클래스를 사용하는 데 문제가 있습니다.
- (void) handleItem:(PFItem *)item{
[item fetchIfNeededInBackgroundWithBlock:^(PFItem *item, NSError *error) {
if (!error) {
if ([item.name isEqualToString:@"Antidote"]) {
NSLog(@"Applied %@", item.name);
NSMutableArray *discardItems = [NSMutableArray array];
for (PFItem *item in self.pfButtonCharacter.itemsApplied) {
if (item.malicious) {
[discardItems addObject:item];
NSLog(@"Removing %@", item.name);
}
}
[PFObject deleteAll:discardItems];
}
}
}];
}
그러나, 의미 론적 오류로 엑스 코드 플래그이 :
내가 fetchIfNeededInBackgroundWithBlock에 PFObject에 PFItem에서 변경하는 경우Incompatible block pointer types sending 'void (^)(PFItem *__strong, NSError *__strong)' to parameter of type 'PFObjectResultBlock' (aka 'void (^)(PFObject *__strong, NSError *__strong)')
, 그것은 작동하지 않습니다,하지만 나는 더 이상 항목의 속성에 액세스 할 수 있습니다. item.name
대신 item[@"name"]
을 수행해야합니다. 당신이 수행하고있는 PFObject
PFItem
A를하고
두 답변 모두 훌륭하지만, 캐스팅하기 전에 클래스를 확인하는 것이 안전하기 때문에 제공하고 있습니다. 둘 다 감사합니다! – user3741732