I'm having trouble understanding how to use subclassed objects with blocks. Here is an example of what I'm trying. PFItem is a subclass of 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];
}
}
}];
}
However, xcode flags this as a semantic error:
Incompatible block pointer types sending 'void (^)(PFItem *__strong, NSError *__strong)' to parameter of type 'PFObjectResultBlock' (aka 'void (^)(PFObject *__strong, NSError *__strong)')
If I change from PFItem to PFObject in fetchIfNeededInBackgroundWithBlock, it works, but then I can no longer access the properties of item. Instead of item.name I need to do item[@"name"].