Featured iPhone Development Resources

Swift Library Providing An Active Record Implemention For Managing Core Data Objects

Some time ago I mentioned the ObjectiveRecord library providing an active record implementation for managing Core Data objects in Objective-C.

Here’s an open source Swift library inspired by ObjectiveRecord providing an implementation of ActiveRecord with a number of nice features from Zaid Daghestani called SwiftRecord.

SwiftRecord provides easy queries, creation, deletion, and saving and you can use dictionaries.

Here is an example from the readme demonstrating the query syntax:

// grab all Events
var events = Event.all() as! [Event]

// all past events before now
var pastEvents = Event.query("when < %@", NSDate()) as! [Event]

// specific event, yes we have support for format&arguments. Note, finding specific events return optional vars
var thisEvent = Event.find("name == %@ AND when == %@", "productQA", NSDate()) as? Event

// Use dictionaries to query too
var birthdayEvents = Event.query(["type":"birthday"]) as! [Event]

// or NSPredicates
var predicate = NSPredicate("type == %@", "meeting")
var meetingEvents = Event.query(predicate) as! [Event]

You can find SwiftRecord on Github here.

A great library for working with Core Data in Swift.