Skip to content

Instantly share code, notes, and snippets.

@torpedo87
Created March 28, 2019 08:58
Show Gist options
  • Save torpedo87/c641de071ec38459df674be386e2415e to your computer and use it in GitHub Desktop.
Save torpedo87/c641de071ec38459df674be386e2415e to your computer and use it in GitHub Desktop.
nsfetchedresultscontroller

NSFetchedResultsController

  • core data 의 fetched results 를 table view에 효율적으로 나타내기 위해 만든 컨트롤러
  • fetched results 의 wrapper
  • A controller that you use to manage the results of a Core Data fetch request and to display data to the user.
  • needed to synchronize a table view with a data source backed by Core Data.
  • performFetch() : After executing this method, you can access the receiver’s the fetched objects with the property fetchedObjects.
  • requires at least one sort descriptor

섹션별로 그루핑

  • sectionNameKeyPath : The key path on the fetched objects used to determine the section they belong to.
  • 원하는 기준에 따라 섹션으로 나눌 수 있다
  • the first sort descriptor’s attribute must match the key path’s attribute.
  • NSFetchedResultsSectionInfo : A protocol that defines the interface for section objects vended by a fetched results controller.

캐싱

  • 섹션별 그루핑은 매우 헤비한 작업이므로 이를 해결하기 위해 코어데이터에 섹션별 캐싱을 한다
  • specifying a cache name on your fetched results controller.
  • init(fetchRequest:managedObjectContext:sectionNameKeyPath:cacheName:)
  • Pre-computed section info is cached to a private directory under this name. If Core Data finds a cache stored with this name, it is checked to see if it matches the fetchRequest. If it does, the cache is loaded directly—this avoids the overhead of computing the section and index information. If the cached information doesn’t match the request, the cache is deleted and recomputed when the fetch happens.

변화를 모니터링

  • NSFetchedResultsControllerDelegate : A delegate protocol that describes the methods that will be called by the associated fetched results controller when the fetch results have changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment