Swift project for populate core data from a JSON
Swift Ruby
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
JSONCoreDataImport.xcodeproj
JSONCoreDataImport
JSONCoreDataImport.podspec
LICENSE
README.md

README.md

JSON Core Data Import

Requirements

  • iOS 8
  • Xcode 8.1+
  • Swift 3.0

Dependency

Install

  pod 'JSONCoreDataImport', :git => 'https://github.com/hours-alone/JSONCoreDataImport.git'

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
}