IPhone : Undefined selector with Objective-C runtime - blocks

on Tuesday, February 24, 2015

I'm trying to create a function where multiple times I do the same thing. I've deceided to go with a block this time. However after writing following code:



- (BOOL)readyForProcessing {
void (^notDeclaredError)(id) = ^(id missingObject) {
NSString *missingObjectName = NSStringFromSelector(@selector(missingObject));
NSString *errorDescription = [NSString stringWithFormat:@"You need to provide %@ property", missingObjectName];
[self configureErrorWithLocalizedDescription:errorDescription];
};

if (!self.delegate) notDeclaredError(self.delegate);

return self.error ? NO : YES;
}


I get a warning in the line, where I declare missingObjectName.



Undeclared selector 'missingObject'


I know it will probably try to make a NSString from missingObject instead of delegate. How to pass it this way, that the output will be delegate and the code will be inside the block?


0 comments:

Post a Comment