Originally created by @wm-j-ray on GitHub (May 30, 2016).
John,
I have a collection of predicates that I'd like to use to create NSFetchedResultsControllers. I realize this is defeating a lot of the purpose of CoreStore, but nonetheless. I've tried:
CoreStore.mainContext and CoreStore.defaultStack.mainContext
Originally created by @wm-j-ray on GitHub (May 30, 2016).
John,
I have a collection of predicates that I'd like to use to create NSFetchedResultsControllers. I realize this is defeating a lot of the purpose of CoreStore, but nonetheless. I've tried:
CoreStore.mainContext and CoreStore.defaultStack.mainContext
```
lazy var fetchedResultsController: NSFetchedResultsController = {
// Initialize Fetch Request
let fetchRequest = NSFetchRequest(entityName: "Item")
// Add Sort Descriptors
let sortDescriptor = NSSortDescriptor(key: "createdAt", ascending: true)
fetchRequest.sortDescriptors = [sortDescriptor]
// Initialize Fetched Results Controller
let fetchedResultsController = NSFetchedResultsController(fetchRequest: fetchRequest, managedObjectContext: self.managedObjectContext, sectionNameKeyPath: nil, cacheName: nil)
// Configure Fetched Results Controller
fetchedResultsController.delegate = self
return fetchedResultsController
}()
```
adam
added the question label 2025-12-29 15:23:26 +01:00
@JohnEstropia commented on GitHub (May 31, 2016):
You can use `NSFetchedResultsController.createFor(...)` to create a CoreStore-managed controller:
``` swift
let controller = NSFetchedResultsController.createFor(
CoreStore.defaultStack,
From(Item),
OrderBy(.Ascending("createdAt"))
)
controller.delegate = self
return controller
```
If you have raw `NSPredicate` and `NSSortDescriptor`s, `Where` clauses and `OrderBy` clauses accept them in their initializers
``` swift
let controller = NSFetchedResultsController.createFor(
CoreStore.defaultStack,
From(Item),
Where(yourPredicate),
OrderBy(yourSortDescriptors)
)
```
@wm-j-ray commented on GitHub (May 31, 2016):
Thanks John. I'm learning albeit slowly.
On May 30, 2016, 6:21 PM -0400, John Estropianotifications@github.com, wrote:
> You can useNSFetchedResultsController.createFor(...)to create a CoreStore-managed controller:
>
> letcontroller=NSFetchedResultsController.createFor( CoreStore.defaultStack, From(Item), OrderBy(.Ascending("createdAt")) ) controller.delegate=selfreturncontroller
>
> If you have rawNSPredicateandNSSortDescriptors,Whereclauses andOrderByclauses accept them in their initializers
>
> letcontroller=NSFetchedResultsController.createFor( CoreStore.defaultStack, From(Item), Where(yourPredicate), OrderBy(yourSortDescriptors) )
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly,view it on GitHub(https://github.com/JohnEstropia/CoreStore/issues/77#issuecomment-222560925), ormute the thread(https://github.com/notifications/unsubscribe/AAvDJPxhgMQRHjI6bxg0z4Jx1oicxbBnks5qG2LNgaJpZM4IqCef).
If you don't need an NSFetchedResultsController per se, I recommend you use ListMonitors instead. They're much more type-safe and handles a lot of NSFetchedResultsController bugs, and they also support "multiple delegates".
@JohnEstropia commented on GitHub (May 31, 2016):
If you don't need an `NSFetchedResultsController` per se, I recommend you use `ListMonitor`s instead. They're much more type-safe and handles a lot of NSFetchedResultsController bugs, and they also support "multiple delegates".
I'm going to give it a shot. I want to start playing around with that DTTableManager library that abstracts out a lot of the lower level mechanics of tableviews and its just pure FRC. (At first blush).
I used to use TLIndexPathTools, very good but it's ObjC and I am trying to make the transition to Swift and get more toward a Clean Swift architecture.
If you don't need anNSFetchedResultsControllerper se, I recommend you useListMonitors instead. They're much more type-safe and handles a lot of NSFetchedResultsController bugs, and they also support "multiple delegates".
@wm-j-ray commented on GitHub (May 31, 2016):
I'm going to give it a shot. I want to start playing around with that DTTableManager library that abstracts out a lot of the lower level mechanics of tableviews and its just pure FRC. (At first blush).
I used to use TLIndexPathTools, very good but it's ObjC and I am trying to make the transition to Swift and get more toward a Clean Swift architecture.
Again, thanks so much for the help.
On May 30, 2016, 10:03 PM -0400, John Estropianotifications@github.com, wrote:
> If you don't need anNSFetchedResultsControllerper se, I recommend you useListMonitors instead. They're much more type-safe and handles a lot of NSFetchedResultsController bugs, and they also support "multiple delegates".
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly,view it on GitHub(https://github.com/JohnEstropia/CoreStore/issues/77#issuecomment-222577005), ormute the thread(https://github.com/notifications/unsubscribe/AAvDJIJjcM9k43imyJyzdjo4HfLASxf1ks5qG5cLgaJpZM4IqCef).
If your app still have Objective-C code left you might want to play with CoreStore 2.0 (see corestore2_develop branch).
All CoreStore Swift types have their ObjectiveC counterparts (and bridgeable back and forth).
Just to give you more options :)
I'll close this issue for now. Feel free to ask anything else anytime!
@JohnEstropia commented on GitHub (May 31, 2016):
If your app still have Objective-C code left you might want to play with CoreStore 2.0 (see corestore2_develop branch).
All CoreStore Swift types have their ObjectiveC counterparts (and bridgeable back and forth).
Just to give you more options :)
I'll close this issue for now. Feel free to ask anything else anytime!
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Originally created by @wm-j-ray on GitHub (May 30, 2016).
John,
I have a collection of predicates that I'd like to use to create NSFetchedResultsControllers. I realize this is defeating a lot of the purpose of CoreStore, but nonetheless. I've tried:
CoreStore.mainContext and CoreStore.defaultStack.mainContext
@JohnEstropia commented on GitHub (May 31, 2016):
You can use
NSFetchedResultsController.createFor(...)to create a CoreStore-managed controller:If you have raw
NSPredicateandNSSortDescriptors,Whereclauses andOrderByclauses accept them in their initializers@wm-j-ray commented on GitHub (May 31, 2016):
Thanks John. I'm learning albeit slowly.
On May 30, 2016, 6:21 PM -0400, John Estropianotifications@github.com, wrote:
@JohnEstropia commented on GitHub (May 31, 2016):
If you don't need an
NSFetchedResultsControllerper se, I recommend you useListMonitors instead. They're much more type-safe and handles a lot of NSFetchedResultsController bugs, and they also support "multiple delegates".@wm-j-ray commented on GitHub (May 31, 2016):
I'm going to give it a shot. I want to start playing around with that DTTableManager library that abstracts out a lot of the lower level mechanics of tableviews and its just pure FRC. (At first blush).
I used to use TLIndexPathTools, very good but it's ObjC and I am trying to make the transition to Swift and get more toward a Clean Swift architecture.
Again, thanks so much for the help.
On May 30, 2016, 10:03 PM -0400, John Estropianotifications@github.com, wrote:
@JohnEstropia commented on GitHub (May 31, 2016):
If your app still have Objective-C code left you might want to play with CoreStore 2.0 (see corestore2_develop branch).
All CoreStore Swift types have their ObjectiveC counterparts (and bridgeable back and forth).
Just to give you more options :)
I'll close this issue for now. Feel free to ask anything else anytime!