Latest 1.0.0
Homepage https://github.com/sergdort/SwiftImport
License MIT
Platforms ios 8.0, osx 10.9, requires ARC
Authors

Build Status
Version
License
Platform

Requirements

Usage

import SwiftImport

extension User {

    @NSManaged var lastName: String?
    @NSManaged var name: String?
    @NSManaged var userId: NSNumber?
    @NSManaged var createdEvents: NSSet?
    @NSManaged var homeCity: City?

}

extension User {
   override class func mapped() -> [String : String] { // if keys are the same dont need to provide map
      return [ "userId" : "id", "lastName" : "last_name", "homeCity" : "home_city", "createdEvents" : "events"]
   }

   override class func relatedByAttribute() -> String {
      return "userId"
   }

   override class func relatedJsonKey() -> String {
      return "id"
   }

}

...

do {

    let data = //...data from responce or something else
    let user = try SwiftImport<User>.importObject <^> JSONObject -<< JSONObjectWithData -<< data <*> context
} catch {
    //handle error here (ImportError.InvalidJSON)
}

...

or if u prefer normal  sintax ;)

do {
    let users = try SwiftImport<User>.importObjects(json)(context: context)
} catch {
    handle error
}

Installation

SwiftImport is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "SwiftImport"

TODO

Author

sshulga, [email protected]

License

SwiftImport is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SwiftImport",
    "version": "1.0.0",
    "summary": "Type safe core data from JSON import library",
    "description": "This is type safe core data import lib from JSON inspired by the post https://robots.thoughtbot.com/efficient-json-in-swift-with-functional-concepts-and-generics",
    "homepage": "https://github.com/sergdort/SwiftImport",
    "license": "MIT",
    "authors": {
        "sergdort": "[email protected]"
    },
    "source": {
        "git": "https://github.com/sergdort/SwiftImport.git",
        "tag": "1.0.0"
    },
    "social_media_url": "https://twitter.com/SergDort",
    "platforms": {
        "ios": "8.0",
        "osx": "10.9"
    },
    "requires_arc": true,
    "source_files": "Pod/Classes/**/*.swift"
}

Pin It on Pinterest

Share This