0
Core Data Bookmark IDとJSON Web API IDを一致させることができず、JSON APIからCore Dataに画像を保存できません。コアデータIDとWeb JSON API IDが一致しませんか?
Mainclass
import UIKit
import MapKit
import CoreLocation
import SDWebImage
import CoreData
class InfoViewController: UIViewController , MKMapViewDelegate,CLLocationManagerDelegate{
var get_details : schools?
var bookmark : [Bookmark] = []
var bookmark_details : Bookmark?
override func viewDidLoad() {
super.viewDidLoad()
}
func bookmarktoCoredata(){
let alert = UIAlertController(title: "Add BookMark", message: "", preferredStyle: .alert)
let add = UIAlertAction(title: "Add", style: .default){
(action) in
// for bkms in self.bookmark
// {
// if ((bkms.name)) == ((self.get_details?.name)!){
//
// print("same name")
//
// }else{
// print("not same")
// }
// }
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let task = Bookmark(context: context)
if (task.bookmark_id) == Int16((self.get_details?.schoolid)!){
print("same id")
}
else
{
print("not same id")
task.bookmark_id = Int16((self.get_details?.schoolid)!)
task.name = self.get_details?.name
task.address = self.get_details?.address
task.district = self.get_details?.district
task.country = self.get_details?.country
task.phone = self.get_details?.phone
task.email = self.get_details?.email
task.website = self.get_details?.website
task.institution = self.get_details?.institution_type
task.establishment = self.get_details?.establishment_date
task.admission_open = self.get_details?.admission_open_from
task.admission_end = self.get_details?.admission_open_from
task.latitude = (self.get_details?.latitude)!
task.longitude = (self.get_details?.longitude)!
task.bookmark_type = "school"
// let img = UIImage(named: "App.png") //Sending direct image its working
let img = UIImage(named: (self.get_details?.logo)!) //by Json it sendong nil
let imgdata = UIImageJPEGRepresentation(img!, 1)
task.logo = imgdata! as NSData
(UIApplication.shared.delegate as! AppDelegate).saveContext()
}
}
let cancel = UIAlertAction(title: "Cancel", style: .cancel){
(alert) in
// JLToast.makeText("Your Bookmark Cancel !!").show()
}
alert.addAction(add)
alert.addAction(cancel)
present(alert, animated: true, completion: nil)
}
私のコードが間違っている理由を私は理解することはできません。
私も、このいずれかを試してみるが、私はそのすべての値は、あなたが修正を試してみました前から –
あなたが保存されている可能性のあるデータを複製保存一致し得ていないのです。アプリを消去して再インストールしてください。これからは、新しいIDを持っている場合にのみ新しいブックマークを保存します。 – pesch
私はそれを試しましたが、コアデータのブックマークエンティティ –