I’m trying to set error message if something is wrong, but I get
This class is not key value coding-compliant for the key NSLocalizedDescription
Here is the code I use
-(id)getMoneyFromAccount:(int) sum error:(NSError **)error
{
if(self.balance - sum < 0)
{
NSDictionary *details = [NSDictionary dictionary];
[details setValue:@"You don't have enough money" forKey:NSLocalizedDescriptionKey];
*error = [NSError errorWithDomain:@"money" code:200 userInfo:details];
return nil;
}
self.balance = self.balance - sum;
return [NSNumber numberWithInt:self.balance];
}
You are calling
setValue:forKey:where you should be callingsetObject:forKey:In addition, you have to change from
NSDictionarytoNSMutableDictionaryor set the values in the initializer:The
setValue:forKey:would work with a mutable dictionary, but it’s better to callsetObject:forKey:directly.