Last active
August 29, 2015 14:20
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// 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