在Core Data中保存bool值

时间:2021-05-03 16:31:34

I want to make an alarm app, and I have a uitableview, on wich row I have a switch, on or off, now I want to save in core data what user selected, on or off.... Here is my code where I try to save in Core Data...

我想制作一个报警应用程序,我有一个uitableview,我有一个开关,打开或关闭,现在我想保存用户选择,开启或关闭的核心数据....这是我的代码在哪里我尝试保存在Core Data中......

CoreDataStack *coreDataStack = [CoreDataStack defaultStack];
NSNumber *numberAsBool = [NSNumber numberWithBool:self.switchLabel.on];
self.entry.active = numberAsBool;
[coreDataStack saveContext];

But everytime the value is 0. Anyone have an idea??

但每次价值为0.任何人都有一个想法?

1 个解决方案

#1


Instead of:

NSNumber *numberAsBool = [NSNumber numberWithBool:self.switchLabel.on];

It should be:

它应该是:

NSNumber *numberAsBool = [NSNumber numberWithBool:[self.switchLabel isOn]];

#1


Instead of:

NSNumber *numberAsBool = [NSNumber numberWithBool:self.switchLabel.on];

It should be:

它应该是:

NSNumber *numberAsBool = [NSNumber numberWithBool:[self.switchLabel isOn]];