Dynamically change the sort descriptor for the result controller

Is there a way for the sort descriptor to be dynamically set for the selected result controller on iOS?

For example, I want the results of the master data returned to me to be sorted depending on the setting of the segmented control in the navigation title bar. A user can click a segmented control to sort by price or priority.

Then I need a controller of the results to return and display information about the kernel data, sorted into sections based on this segmented control value.

I know how to set sort descriptors first, but I don't know how to change / update it dynamically. Since the function - (NSFetchedResultsController *)fetchedResultsController lazy loaded, usually it always returns only frc, which was created the first time (thus returning the initial setting of the sort descriptor)?

Will I do something like storing the segmented value of the control in sharedPreferences, and then when it changes, set my fetchedResultsController to nil so that a new one is generated? Then, in the fetchedResultsController function, can I create my sortDescriptor based on this sharedPreferences parameter?

+4
source share
1 answer

You control it. For example, you can release the controller when the segmented control is updated and reload the call in the table. This will cause the controller to be rebuilt with a new type.

There are other solutions, but they depend on the design of your application.

+3
source

Source: https://habr.com/ru/post/1313263/


All Articles