【发布时间】:2016-08-13 23:47:17
【问题描述】:
我想在单击按钮时将我的数据保存到核心数据这里是我现在的操作按钮代码let app = UIApplication.sharedApplication().delegate as! AppDelegate
let context = app.managedObjectContext
let entity = NSEntityDescription.entityForName("Cart", inManagedObjectContext: context)
let cart = Cart(entity: entity!, insertIntoManagedObjectContext: context) 但现在唯一的问题是我不知道如何在这里保存是我解析 json 的代码
Alamofire.request(.GET, url!, headers: headers).responseJSON { (response) in
let result = response.result
if response.result.isSuccess{
let jsonObj = JSON(result.value!)
if let x = jsonObj["Items"].array {
x.forEach
{
if let uw = ($0["name"]).string{
print(uw)
let qw = ($0["image"]).string
if let rw = ($0["price"]).int{
if let hu = ($0["id"]).int{
print(hu)
let foo = Rest(name: uw, imageUrl: qw!, price: "₦\(rw)")
self.rest.append(foo)
}
}
}
}
dispatch_async(dispatch_get_main_queue()) {
self.tableView.reloadData()
actInd.stopAnimating()
}
}
}
所以我有一个名为 rest 的数组,我想在其中获取 tableview 的数据。我想保存每个单元格进入coredata的信息这里是app的截图
因此,当点击确定按钮时,它会将项目保存到 coredata 这是我的代码,以防你需要code
【问题讨论】:
标签: ios arrays swift uitableview core-data