EXC_BAD_ACCESS error when trying to change Bool property

后端 未结 4 2004
甜味超标
甜味超标 2020-12-17 18:05

I\'m trying to change a Bool property and am receiving an EXC_BAD_ACCESS error.

I\'m using XCode 6 and Swift.

The note property saves fine but t

相关标签:
4条回答
  • 2020-12-17 18:50

    You can use a swift Bool with an NSManagedObject - no need for the NSNumber nonsense. But you need to make sure that in the core data editor, the class is not empty. Enter your objects' name.

    0 讨论(0)
  • 2020-12-17 18:56

    I had almost this exactly problem.

    Boolean works in Core Data.

    The problem I had was in the Core Data Editor under 'CONFIGURATIONS' and 'C' Default. I did not have my entity linked to the correct class.

    0 讨论(0)
  • 2020-12-17 18:58

    I'm just considering filing a bug as I have the same issue but if your really want to use Bool still then a workaround is to use this method:

    setValue(true, forKey: "completed")
    
    0 讨论(0)
  • 2020-12-17 19:00

    Had the same problem, the solution is indeed to use NSNumber in the @NSManaged property. Additionally you could define a computed Bool property so that you can work with the scalar Boolean in your business logic and not with the NSNumber.

    var isCompleted: Bool {
    get {
        return completed == NSNumber(bool: true)
    }
    set {
        completed = NSNumber(bool: newValue)
    }
    }
    
    0 讨论(0)
提交回复
热议问题