mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-04-21 00:11:25 +02:00
smart way to load entityNames from the model file
This commit is contained in:
@@ -41,9 +41,7 @@ extension NSManagedObjectContext {
|
||||
public func fetchOne<T: NSManagedObject>(entity: T.Type, _ queryClauses: [FetchClause]) -> T? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
fetchRequest.entity = NSEntityDescription.entityForName(
|
||||
entity.entityName,
|
||||
inManagedObjectContext: self)
|
||||
fetchRequest.entity = self.entityDescriptionForEntityClass(entity)
|
||||
fetchRequest.fetchLimit = 1
|
||||
fetchRequest.resultType = .ManagedObjectResultType
|
||||
|
||||
@@ -75,9 +73,7 @@ extension NSManagedObjectContext {
|
||||
public func fetchAll<T: NSManagedObject>(entity: T.Type, _ queryClauses: [FetchClause]) -> [T]? {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
fetchRequest.entity = NSEntityDescription.entityForName(
|
||||
entity.entityName,
|
||||
inManagedObjectContext: self)
|
||||
fetchRequest.entity = self.entityDescriptionForEntityClass(entity)
|
||||
fetchRequest.fetchLimit = 0
|
||||
fetchRequest.resultType = .ManagedObjectResultType
|
||||
|
||||
@@ -109,9 +105,7 @@ extension NSManagedObjectContext {
|
||||
public func queryCount<T: NSManagedObject>(entity: T.Type, _ queryClauses: [FetchClause]) -> Int {
|
||||
|
||||
let fetchRequest = NSFetchRequest()
|
||||
fetchRequest.entity = NSEntityDescription.entityForName(
|
||||
entity.entityName,
|
||||
inManagedObjectContext: self)
|
||||
fetchRequest.entity = self.entityDescriptionForEntityClass(entity)
|
||||
|
||||
for clause in queryClauses {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user