Skip to content

Instantly share code, notes, and snippets.

@ravero
Last active August 29, 2015 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravero/852e32e1e6fc5044d153 to your computer and use it in GitHub Desktop.
Save ravero/852e32e1e6fc5044d153 to your computer and use it in GitHub Desktop.
A template of a SwiftyIO Data Context Class. This is code is intended to be used as Xcode Snippet.
/// Swifty IO Context Class
class <# Model Name #>Context : BaseDataContext {
//
// MARK: - Singleton
class var sharedInstance: <# Context Class #> {
struct Singleton {
static var instance: <# Context Class #>?
static var token: dispatch_once_t = 0
}
dispatch_once(&Singleton.token) {
Singleton.instance = <# Context Class #>()
}
return Singleton.instance!
}
//
// MARK: - Entity Constants
static let <# Entity Name Field Constant #>_ENTITY_NAME = "<# Entity Name #>"
static let <# Entity Key Field Constant #>_ENTITY_KEY = "<# Entity Key Field Name #>"
//
// MARK: - Entity Data Source Properties
var <# Entity Property #>: EntityDataSource<<# Entity Type #>, <# Primary Key Field Type #>>!
//
// MARK: - Initializers
init() {
super.init(resourceName: "<# Model Name #>")
// Entities Initialization
if let moc = managedObjectContext {
self.<# Entity Property #> = EntityDataSource(managedObjectContext: moc,
entityName: <# Entity Name Field Constant #>,
entityKeyName: <# Entity Key Field Constant #>,
entityKeyGeneration: PrimaryKeyGeneration<# Primary Key Generation #>);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment