Question

I am trying to return a subset of my NSMutableArray (MessageArray) with the following code. MessageArray contains an NSDictionary, one of the keys being FriendStatus. I get a strange error which I know is a DUH syntax issue. "error. void value not ignored as it ought to be".

-(NSMutableArray*)FriendMessageArray {  

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"FriendStatus == 1"];

NSMutableArray *filtered = [MessageArray filterUsingPredicate:predicate];
return filtered;

}

Was it helpful?

Solution

"void value not ignored as it ought to be" means that a method with a signature that starts with (void) is being used to assign a value or object to a variable. What's the signature for filterUsingPredicate? does it start with (void) ?

OTHER TIPS

I'm assuming "MessageArray" is an instance variable (never name instance variables this way; you should have a property called -messages and access it with self.messages). I'l further assume that it is an NSMutableArray or else you'd be getting warnings from the compiler.

NSMutableArray -filterUsingPredicate: modifies the array itself, returning void. The method you want is -filteredArrayUsingPredicate: which returns an array. The fact that the former is a verb and the latter is a noun indicates this fact even without reading the docs. Cocoa naming is extremely consistent, which is why I mention it in the first paragraph. Pay attention to the names and you will have far fewer bugs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top