I am trying to switch the BOOLEAN value of the property ‘isLiked’ as seen in the code below
//BOOL isLiked is defined in the header file as property of answer class
- (void)buttonPressed
{
NSLog(@"button pressed");
if ([btnType isEqualToString:@"like"])
{
self.answer.isLiked = !self.answer.isLiked;
NSLog(@"answer is: %i",self.answer.isLiked);
}
}
When I print out the value of ‘self.answer.isLiked’ I see that the value returned is always ‘0’. How can I switch the values??
I’m guessing
self.answeris, in fact, nil. That will causeself.answer.isLiked = !self.answer.isLikedto do nothing at all, and will cause your NSLog to actually be logging the integer value of nil, which is 0.