0
我的數據庫中有一個名爲「Me」的實體,它有一個名爲「loggedIn」的BOOL屬性。我該屬性的默認值設置爲NO,像這樣:爲什麼我的實體的BOOL類型屬性返回YES,即使它被設置爲NO?
只是爲了確保它被設置爲NO,我還要把它設置程序,但它仍然是顯示了YES日誌中:
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"Me"];
NSError *err;
NSUInteger count = [context countForFetchRequest:request error:&err];
if (count == 0) {
NSManagedObject *me = [NSEntityDescription insertNewObjectForEntityForName:@"Me" inManagedObjectContext:context];
}
NSArray *fetchedObjects = [context executeFetchRequest:request error:&err];
[[fetchedObjects objectAtIndex:0] setValue:[NSNumber numberWithBool:NO] forKey:@"loggedIn"];
NSString *amIYesOrNo = [NSString stringWithFormat:@"%@", ([[fetchedObjects objectAtIndex:0] valueForKey:@"loggedIn"] ? @"YES" : @"NO")];
NSLog(amIYesOrNo);
amIYesOrNo always should show up YES when it should be no。到底是怎麼回事?
你能舉個例子嗎? – zakdances 2012-04-27 15:39:30
'BOOL yesOrNo = [[NSNumber numberWithBool:NO] boolValue];' – 2012-04-27 15:44:03