Swift project for populate core data from a JSON
Swift Ruby
Latest commit 556c84c Mar 21, 2017 @hours-alone committed on GitHub Update README.md

README.md

JSON Core Data Import

Requirements

  • iOS 8
  • Xcode 8.1+
  • Swift 3.0

Dependency

Features

  • Truncate and import data for populate a Core Data from a JSON
  • During importation, detect and download image
  • You can used DispatchGroup for be alerted when donwload is finished

Example

Only data :

  • JSON :
{
	"EntityName": [{
		"id": 1,
		"name": "Suroh"
	}, {
		"id": 2,
		"name": "Horus"
	}]
}
  • Code :
let appDel = UIApplication.shared.delegate as! AppDelegate
let context = appDel.managedObjectContext

let jsonCoreDataImport = JSONCoreDataImport(delegateClass: self, managedObjectContext: context)
jsonCoreDataImport.importJSON(json)

Data + Image + DispatchGroup :

  • JSON :
{
	"EntityName": [{
		"id": 1,
		"name": "Suroh",
		"image": "suroh.png"
	}, {
		"id": 2,
		"name": "Horus",
		"image": "horus.png"
	}]
}
  • Code :
let group = DispatchGroup()

let appDel = UIApplication.shared.delegate as! AppDelegate
let context = appDel.managedObjectContext

let pathsDoc: URL = FileManager.default.containerURL(forSecurityApplicationGroupIdentifier: "group.fr.hours-alone")!

let jsonCoreDataImport = JSONCoreDataImport(delegateClass: self, managedObjectContext: context)
//if you defined "urlCDNImage", url = urlCDNImage + value inside column image else url = value inside column image.
jsonCoreDataImport.importJSON(json, groupList: group,withImage: true, imageColumnName:"image",urlCDNImage: "http://cdn.mywebsite.fr/",pathsDoc: pathsDoc)

group.notify(queue: DispatchQueue.main) {
  //called when download is finished
}