Skip to content

Instantly share code, notes, and snippets.

@kreeger
Created January 8, 2019 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kreeger/7b007253c7cb8359428ec6ca1e6bd1b6 to your computer and use it in GitHub Desktop.
Save kreeger/7b007253c7cb8359428ec6ca1e6bd1b6 to your computer and use it in GitHub Desktop.
Example model implementation code for the blog post "Flapjack" on O'Reilly's engineering blog.
extension Pancake: DataObject {
// The type of your primary key, if you have one of your own.
public typealias PrimaryKeyType = String
// The name of the entity as Core Data knows it.
public static var representedName: String {
return "Pancake"
}
// The key path to your model's primary key.
public static var primaryKeyPath: String {
return #keyPath(identifier)
}
// An array of sorting criteria.
public static var defaultSorters: [SortDescriptor] {
return [
SortDescriptor(#keyPath(flavor), ascending: true, caseInsensitive: true),
SortDescriptor(#keyPath(radius), ascending: false)
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment