Latest 0.1.0
Homepage https://github.com/kylebshr/LiteData
License MIT
Platforms ios 9.0, requires ARC

LiteData Logo

Version
License
Platform

About

LiteData provides a very simple core data stack, and a few protocols to make it nice to work with NSManagedObjects and the like. It is heavily influenced by the talk Modern Core Data by Daniel Eggert.

Because it’s so lightweight there are couple caveats:

  • NSManagedObject class names must match the entity name.
  • Though it makes the simple things very easy, the more complicated things must be done almost completely manually.

That being said, I’m definitely willing to add more features. This is my first foray into CoreData, so as I use it more, this library will evolve and improve.

Documentation

Jazzy docs available here.

Getting Started

LiteData provides an easy to use core data stack with sensible defaults. Creating a stack is as simple as telling it the model name:

var stack: LiteStack!

do {
    try stack = LiteStack(modelName: "Model")
} catch {
    fatalError("Error setting up stack: (error)")
}

Conforming to ManagedObjectType gives your NSManagedObjects the power of LiteData. Return some default descriptors, and you get effortless fetch requests and fetched results controllers:

extension Post: ManagedObjectType {
    static var defaultSortDescriptors: [NSSortDescriptor] {
        return [NSSortDescriptor(key: "date", ascending: true)]
    }
}

/* Later */

// Create a post
let post: Post = stack.context.insert()

// Create a fetched results controller
let frc = stack.context.sortedFetchedResults(ofType: Post.self)

// Get a simple fetch request
let request = Post.sortedFetchRequest

There’s also a KeyCodable protocol you can implement if you’d like to, which makes it much easier and safer to work with keys:

extension Post: KeyCodable {
    enum Key: String {
        case text
        case likes
        case date
        case identifier
    }
}

/* Later */

extension Post: ManagedObjectType {
    static var defaultSortDescriptors: [NSSortDescriptor] {
        let dateDescriptor = NSSortDescriptor(key: Key.date.rawValue, ascending: true)
        let likesDescriptor = NSSortDescriptor(key: Key.likes.rawValue, ascending: true)
        return [dateDescriptor, likesDescriptor]
    }
}

Requirements

  • Xcode 7.3+
  • iOS 9+

Installation

LiteData is available through CocoaPods and Carthage.

CocoaPods

use_frameworks!

pod "LiteData"

Carthage

github "kylebshr/LiteData"

License

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

Latest podspec

{
    "name": "LiteData",
    "version": "0.1.0",
    "license": "MIT",
    "description": "LiteData is a very small framework to make working with Core Data a little easier and swiftier. It doesn't do a lot, but it makes the basics very simple.",
    "summary": "A very light and swifty core data stack",
    "homepage": "https://github.com/kylebshr/LiteData",
    "social_media_url": "https://twitter.com/kylebshr",
    "authors": "Kyle Bashour",
    "source": {
        "git": "https://github.com/kylebshr/LiteData.git",
        "tag": "0.1.0"
    },
    "source_files": "Source/*.swift",
    "platforms": {
        "ios": "9.0"
    },
    "requires_arc": true
}

Pin It on Pinterest

Share This