我有很多信息要重新填充我的数据库,这就是我的工作方式:
=
它是完整代码的一小部分,我该如何最小化这个?
答案 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")
}
}