swift coredate NSEntityDescription insertInto got EXC_BAD_ACCESS use Int32 or Bool type

28 views Asked by At

Evn: xcode Version 15.0 + swift5

coredate DataSaved Entities DataSaved Entities

in class

public final class DataSaved: NSManagedObject {

    @NSManaged public var amount: String?
    @NSManaged public var index: Int32
    @NSManaged public var isSelected: Bool
    @NSManaged public var savedUrl: String?

    public init(context: NSManagedObjectContext,
                index1: Int32,
                isPrivate1: Bool,
                isSelected1: Bool) {
      
        guard let entity = NSEntityDescription.entity(forEntityName: "DataSaved", in: context) else {
            fatalError("No such Entity: DataSaved")
        }
          
        super.init(entity: entity, insertInto: context)
      
        self.amount = "tom"
        self.savedUrl = "lili"
        self.index = index1  // runtime failed 
        self.isSelected = isSelected1 // runtime failed 
    }
//if use setValue can succeed
setValue(index1, forKey: "index") // runtime succeed
setValue(isSelected1, forKey: "isSelected") // runtimesucceed*

just int and bool have this issue , string is well. who is know why ?

i test use setValue medthod can set int32 or bool type but direct use self.index = Int32(123) will crash when runtime

0

There are 0 answers