0
我从网络获取电话和JSON解析它的数据为:如何从一个阵列的数据复制到核心数据实体
Alamofire.request(url, method: .get, parameters: nil, encoding: JSONEncoding.default)
.responseJSON { response in
if let status = response.response?.statusCode {
switch(status){
case 200:
self.allResponse = response.result.value as! NSDictionary
if let categories = self.allResponse.value(forKey: "categories") as? [[String: AnyObject]] {
for category in categories {
self.categories.append(Category(dict: category))
}
}
self.collectionView.reloadData()
default:
print("error with response status: \(status)")
}
}
}
的代码获取数据,并成功地解析它。现在我想将这些数据保存在我所做的CoreData实体中。我有var categories = [Category]()
中的所有类别,我想用魔法记录将它复制到核心数据的实体中。我之前在CoreData上保存了值,但它们是一个一个的。现在我已经将所有数据堆栈存储在一个数组中,我需要将其存储在coredata中。我怎样才能做到这一点?