2017-04-06 50 views
1

我在我的一個項目中使用了Alecrim CoreData。所有的設置是確定的,但我有1個問題,當配置fetchedResultControllertableView基本上我所做的是IOS swift 3 Alerim核心數據定製FetchRequestController

fileprivate private(set) lazy var fetchedResultsController: FetchRequestController<Movie> = { 

     let query = self.persistentContainer!.viewContext.movies.orderBy(ascending: false, { $0.releaseDate }) 

     return query.toFetchRequestController() 
    }() 

我的問題是我怎麼可以自定義fetchRequestController?例如更改fetchBathSize,fetchlimit, fetchOffset ...?

Anyhelp非常感謝。由於

回答

0

嘗試這個

lazy var fetchedResultsController: NSFetchedResultsController<NSFetchRequestResult> = { 
     // Initialize Fetch Request 
     let fetchRequest = NSFetchRequest<NSFetchRequestResult>(entityName: "Item") 

     // Add Sort Descriptors 
     let sortDescriptor = NSSortDescriptor(key: "age", ascending: true) 
     fetchRequest.sortDescriptors = [sortDescriptor] 

     // Initialize Fetched Results Controller 
     let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: (UIApplication.shared.delegate as! AppDelegate).manageObjectContext, sectionNameKeyPath: nil, cacheName: nil) 

     // Configure Fetched Results Controller 
     fetchedResultsController.delegate = self 

     return fetchedResultsController 
    }() 

Core Data Programming Guide: Fetching Objects

+0

謝謝你好的響應。我正在使用Alecrim CoreData庫。這個班是不同的名字。我正在挖掘源代碼以找出 –

+0

@LêKhánhVinh您是否看到這個https://github.com/Alecrim/AlecrimCoreData#advanced-use –