Q:

Problem with assigning object for key value

I'm trying to initialize some values using in my interface using a dictionary.
This are the values that the dictionary has:
{
  "d":[],
  "tH":123456789213,
  "e":NO,
  "a":"on"
}

To initialize I use the following method:
- (id)initWithDict:(NSDictionary *)dict{

    self = [super initWithDict: dict];
    self.targetHour = [dict objectForKey:@"tH"];
    self.action = [dict objectForKey:@"a"];
    self.days = [dict objectForKey:@"d"];
    self.enabled = [dict objectForKey:@"e"];

    if(!dict[@"id"]){

        self.id = [[NSDate date] timeIntervalSince1970];
    }

    return self;
}

No all the values are correct except self.enabled which for some reason is assigned to YES instead of NO. I can't figure out what's wrong and why it keeps getting the incorrect value.

A:

NO is defined as 0 (though in modern systems it gets there via __objc_no, that's still 0 in this context). You can't put that in a NSDictionary. If you did, it would be the same as nil and act as removing the key.
I suspect this is actually @NO, which is the NSNumber version of the value, and is an object (so can be put in an NSDictionary). (I suspect this because you also have [] in your dictionary, which is also an impossible value in an NSDictionary. Since NO is also invalid JSON, I don't think you're showing us the real data.)
If self.enabled is a BOOL, then when you fetch objectForKey: that will return an object and try to assign the value to the BOOL. The object likely is a tagged pointer, but its overall value is likely non-zero. Non-zero values are true.
I would expect a warning in this case, however. Have you resolved all warnings in this project?

