Reputation: 91969
I have a property on my Model
as
@property (nonatomic) bool *groupOnly;
and my JSON
from API
looks like
{
category = {
groupName = Technology;
id = "b0bddf25-5cce-4184-a589-570fbd39a562";
name = Software;
};
groupOnly = 0;
recurring = 0;
}
When I inspect the type of value for the boolean, I see that it is _NSCFBoolean
I want to store this information as boolean, so I tried
budgetCategoryModel.groupOnly = (bool *) [[[json valueForKey:@"groupOnly"] stringValue] isEqual:@"1"];
but what I get back is nil
What am I doing wrong? What is the recommended way to convert to boolean?
Upvotes: 1
Views: 1013
Reputation: 442
The boolean declaration in your model is incorrect. It should be
@property (nonatomic) BOOL groupOnly;
and the way you should parse the boolean value from you web service response should be like below:
budgetCategoryModel.groupOnly = [[json valueForKey:@"groupOnly"] boolValue];
Hope this helps ..
Upvotes: 1
Reputation: 1869
Try changing your model to declare a bool
rather than a bool
pointer:
@property (nonatomic) bool groupOnly;
Note the lack of a '*'.
Upvotes: 1