Latest 0.3.0
Homepage https://github.com/orangeqc/CoreDataImportKit
License MIT
Platforms ios 8.0, requires ARC
Authors

CoreDataImportKit (CDI) is a no frills, 100% Swift, CoreData importer. Easily define your mappings (i.e. how json data relates to your CoreData attributes) within your CoreData file (*.xcdatamodeld). No extra code needed.

There are no additional CoreData helpers. If you need that, check out MagicalRecord.

The goal of CDI is to stay super lean and easy to maintain. CDI plans on being the best framework written in Swift for implementing importing in your projects.

Installation

It is recommended to add to your project via CocoaPods. Just add the following to your Podfile:

use_frameworks!

target `YourProject` do
    pod 'CoreDataImportKit'
end

Usage

Inside of your xcdatamodeld file you’ll need to define relatedByAttribute on your Entities’s User Info. This should have the name of the attribute used to uniquely identify your entity. In a relational database this would be your primary key.

The default mapping from a dictionary (e.g. you api’s json data) to your entity’s attribute will be based on the attribute’s name. If the two differ, then you can define mappedKeyNamein the User Info of the attribute. This also applies to the relationships.

In order to run an import, you need two things: a mapping and an importer. Once you’ve set that up, you just need to call importRepresentation() to import everything. Here is how you do it in Swift:

let mapping = CDIMapping(entityName: "Company", inManagedObjectContext: localContext)
let cdiImport = CDIImport(externalRepresentation: array, mapping: mapping, context: localContext)
cdiImport.importRepresentation()

In this example array is an array of dictionaries that each define a Company. That is all there is.

Optionally you can use the helper:

Company.cdiImportFromRepresentation(externalRepresentation: array, inContext: localContext)

Check out the wiki (soon) to learn more about the details. You can find out more about the representations and learn to create your own import strategy.

Contributing

Think you have a way of making the importer faster? Have a way of making the code easier to understand? Want to help out with the ROADMAP? Please consider making a pull request.

If you want to discuss changes before writing the code, go ahead and create a Github issue to discuss the potential change. Changes are welcome, just make sure it is tested and that all existing tests continue to pass.

Extra

CoreDataImportKit was written by Ryan Mathews, you can follow me on twitter.

Latest podspec

{
    "name": "CoreDataImportKit",
    "version": "0.3.0",
    "summary": "Swift framework for importing data into CoreData.",
    "homepage": "https://github.com/orangeqc/CoreDataImportKit",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Ryan Mathews": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/orangeqc/CoreDataImportKit.git",
        "tag": "0.3.0"
    },
    "source_files": "CoreDataImportKit/**/*.{h,swift}",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This