小编Jon*_*iro的帖子

UNIQUE约束失败:ZTEMPORADA.Z_PK

我正在研究swift和CoreData,但是在与"Temporada"进行"时间"关系时遇到问题,一个团队可以有几个赛季,一个赛季就是一个团队.

上课时间

import Foundation
import CoreData

@objc(Time)
class Time: NSManagedObject {

@NSManaged var nome: String
@NSManaged var temporada: NSSet

override init(entity: NSEntityDescription, insertIntoManagedObjectContext context: NSManagedObjectContext?) {
    let entity:NSEntityDescription = CoreDataManager.getEntity("Time")
    super.init(entity: entity, insertIntoManagedObjectContext: nil)
}

class func entityDescription() -> (NSEntityDescription){
    let entity:NSEntityDescription = CoreDataManager.getEntity("Time")
    return entity
}

func salvar(){
    let context:NSManagedObjectContext = CoreDataManager.getContext()
    var error:NSError?

    if (!self.inserted) {
        context.insertObject(self)
    }

    context.save(&error)

    if (error != nil){
        NSLog(error!.description)
    }
}
}
Run Code Online (Sandbox Code Playgroud)

Temporada类

import Foundation
import CoreData

@objc(Temporada)
class Temporada: NSManagedObject {

@NSManaged …
Run Code Online (Sandbox Code Playgroud)

sqlite core-data swift

7
推荐指数
1
解决办法
2141
查看次数

标签 统计

core-data ×1

sqlite ×1

swift ×1