Latest 0.1.3
Homepage https://github.com/xxxAIRINxxx/SwCD
License MIT
Platforms ios 8.0, requires ARC
Frameworks UIKit, CoreData
Authors

CI Status
Version
License
Swift 2.1
Platforms iOS
Xcode 7.1+

Lightweight CoreData library. written in Swift.

Requirements

  • Xcode 7.1+
  • iOS 8.0+
  • Swift 2.1
  • CocoaPods 0.36+

Use CoreData In Swift

please see.

http://jamesonquave.com/blog/core-data-in-swift-tutorial-part-1/


Because of the way Swift modules work, we need to make one modification to the core data model.
In the field “Class” under the data model inspector for our entity, LogItem,
we need to specify the project name as a prefix to the class name.
So instead of just specifying “LogItem” as the class,
it needs to say “MyLog.LogItem”, assuming your app is called “MyLog”.

Usage

Setup


// DataModel is your dataModel (DataModel.xcdatamodeld)
SwCD.setup("DataModel", dbRootDirPath: nil, dbDirName: nil, dbName: nil)

Create Entity


// Item is NSManagedObject Subclass
let entity = SwCD.createEntity(Item.self)

Insert


SwCD.insert(Item.self, entities: [entity], completion: { success, error in
  // after call saveWithBlockAndWait function
  if success == true {
      // do something
  } else {
      printlin(error)
  }
})

Find


let predicate = NSPredicate(format: "name == %@", argumentArray: ["bobo james"])

// results is [Item]
let results = SwCD.find(Item.self, predicate: predicate, sortDescriptors: nil, fetchLimit: nil)

FindAll


// results is [Item]
let results = SwCD.all(Item.self, sortDescriptors: nil)

FindFirst


// results is Item?
let result = SwCD.findFirst(Item.self, attribute: "identifier == %@", values: ["1"])

Uodate


// entity is Item?
var entity = SwCD.findFirst(Item.self, attribute: "identifier == %@", values: ["1"])
entity.name = "after"

SwCD.update(Item.self, entities: [entity], completion: nil)

Delete


// entity is Item?
var entity = SwCD.findFirst(Item.self, attribute: "identifier == %@", values: ["1"])

SwCD.delete(Item.self, entities: [entity], completion: nil)

DeleteAll


// Item is NSManagedObject Subclass
SwCD.deleteAll(Item.self, completion: nil)

Installation

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

pod "SwCD"

License

MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "SwCD",
    "version": "0.1.3",
    "summary": "Lightweight CoreData library. written in Swift.",
    "homepage": "https://github.com/xxxAIRINxxx/SwCD",
    "license": "MIT",
    "authors": {
        "Airin": "[email protected]"
    },
    "source": {
        "git": "https://github.com/xxxAIRINxxx/SwCD.git",
        "tag": "0.1.3"
    },
    "platforms": {
        "ios": "8.0"
    },
    "requires_arc": true,
    "source_files": "SwCD/",
    "frameworks": [
        "UIKit",
        "CoreData"
    ]
}

Pin It on Pinterest

Share This