倍数插入核心数据

时间:2017-06-21 12:35:28

标签: ios swift core-data

我有很多信息要重新填充我的数据库,这就是我的工作方式:

=

它是完整代码的一小部分,我该如何最小化这个?

1 个答案:

答案 0 :(得分:0)

试试这个......创建一个公证人数组..

<强>更新

func addNotary(_ context : NSManagedObjectContext,_ notaryArray: Array) -> Bool {

    for index in 0...notaryArray.count - 1
    {
        let notary : Dictionary = notaryArray[index] as! Dictionary
        let notaryFeeGrid = NSEntityDescription.insertNewObject(forEntityName: "NotaryFeeGrid", into: context) as! NotaryFeeGrid

        notaryFeeGrid.id = notary["id"]
        notaryFeeGrid.notaryLoansAmount = notary["notaryLoansAmount"]
        notaryFeeGrid.notaryFeeAmount = notary["notaryFeeAmount"]
    }

    var error: NSError?
    let success = context.save(&error)
    if !success {
        print("Save failed")
    }
}