Swift + CoreData: Can not set a Bool on NSManagedObject subclass - Bug?

前端 未结 6 1332
谎友^
谎友^ 2020-12-16 13:02

I have a little strange issue which I can\'t seem to figure out, I have a simple entity with a custom NSManagedObject subclass:

@objc(EntityTest) class Entit         


        
6条回答
  •  抹茶落季
    2020-12-16 13:22

    Following on from CH Buckingham who is entirely correct. You are attempting to store a primitive type in core data where it is expecting an NSNumber.

    The correct usage would be entity.completed = NSNumber.numberWithBool(false)

    This is also why you cannot retrieve this completed value as a bool directly and thus you would need to write:

    var: Bool? = entity.completed.boolValue()
    

提交回复
热议问题