Swift 3 NSFetchedResultsController #99

Closed
opened 2025-12-29 15:24:36 +01:00 by adam · 5 comments
Owner

Originally created by @colinmorelli on GitHub (Nov 10, 2016).

Making this to track an effort on opening up NSFetchedResultsController for Swift 3. I took a stab at it tonight, but I'm guessing the reason it was commented out in the first place is the same reason I eventually gave up for now: Objective-C generics?

As an alternative (and yes, I acknowledge how hard you've worked to make this not the case), would you consider exposing the NSManagedObjectContext instances? I've actually found multiple use cases for having access to them and am starting to feel that, given the correct caveats all over the documentation, it could be useful to provide.

In any case, is there any way (as is) to use an NSFRC in Swift 3?

Originally created by @colinmorelli on GitHub (Nov 10, 2016). Making this to track an effort on opening up `NSFetchedResultsController` for Swift 3. I took a stab at it tonight, but I'm guessing the reason it was commented out in the first place is the same reason I eventually gave up for now: Objective-C generics? As an alternative (and yes, I acknowledge how hard you've worked to make this not the case), would you consider exposing the `NSManagedObjectContext` instances? I've actually found multiple use cases for having access to them and am starting to feel that, given the correct caveats all over the documentation, it could be useful to provide. In any case, is there any way (as is) to use an NSFRC in Swift 3?
adam added the fixed label 2025-12-29 15:24:36 +01:00
adam closed this issue 2025-12-29 15:24:36 +01:00
Author
Owner

@JohnEstropia commented on GitHub (Nov 10, 2016):

@colinmorelli Thanks for bringing this up! As you have suspected, I removed the NSFetchedResultsController factory methods because during the Swift 3 beta builds there was no way to cast Objective-C "generic" types to each other:

let request: NSFetchRequest<NSFetchRequestResult> = // ...

return CoreStoreFetchedResultsController(
    // ...
    fetchRequest: request // error: cannot cast from NSFetchRequest<NSFetchRequestResult> to NSFetchRequest<NSManagedObject>
)

Fortunately Swift 3 now allows inter-casting with as!. I'll try to recover the commented-out code and see how much we can still use

@JohnEstropia commented on GitHub (Nov 10, 2016): @colinmorelli Thanks for bringing this up! As you have suspected, I removed the NSFetchedResultsController factory methods because during the Swift 3 beta builds there was no way to cast Objective-C "generic" types to each other: ``` swift let request: NSFetchRequest<NSFetchRequestResult> = // ... return CoreStoreFetchedResultsController( // ... fetchRequest: request // error: cannot cast from NSFetchRequest<NSFetchRequestResult> to NSFetchRequest<NSManagedObject> ) ``` Fortunately Swift 3 now allows inter-casting with `as!`. I'll try to recover the commented-out code and see how much we can still use
Author
Owner

@JohnEstropia commented on GitHub (Nov 10, 2016):

As an alternative (and yes, I acknowledge how hard you've worked to make this not the case), would you consider exposing the NSManagedObjectContext instances? I've actually found multiple use cases for having access to them and am starting to feel that, given the correct caveats all over the documentation, it could be useful to provide.

Can you share these use cases? I'm trying out an architecture right now where the context can be accessed if needed, BUT I'd like it to be a last resort and if there are use cases where the context needs to be exposed I'd prefer that CoreStore has it's own abstraction over that.

@JohnEstropia commented on GitHub (Nov 10, 2016): > As an alternative (and yes, I acknowledge how hard you've worked to make this not the case), would you consider exposing the NSManagedObjectContext instances? I've actually found multiple use cases for having access to them and am starting to feel that, given the correct caveats all over the documentation, it could be useful to provide. Can you share these use cases? I'm trying out an architecture right now where the context can be accessed if needed, BUT I'd like it to be a last resort and if there are use cases where the context needs to be exposed I'd prefer that CoreStore has it's own abstraction over that.
Author
Owner

@JohnEstropia commented on GitHub (Nov 11, 2016):

@colinmorelli NSFetchedResultsController utilities are available again!
For usage samples, see
33a5c123aa (diff-a64622bdb6bd86124110367af47fe690R251) for Objective-C,
or 33a5c123aa (diff-17dc834c37c9b798806970e232364293R41) for Swift 3.

As for API's to expose the internal NSManagedObjectContext, please wait for a new protocol in an upcoming version I am currently implementing.

@JohnEstropia commented on GitHub (Nov 11, 2016): @colinmorelli NSFetchedResultsController utilities are available again! For usage samples, see https://github.com/JohnEstropia/CoreStore/commit/33a5c123aabce25de84559f421a345316a77ba6d#diff-a64622bdb6bd86124110367af47fe690R251 for Objective-C, or https://github.com/JohnEstropia/CoreStore/commit/33a5c123aabce25de84559f421a345316a77ba6d#diff-17dc834c37c9b798806970e232364293R41 for Swift 3. As for API's to expose the internal NSManagedObjectContext, please wait for a new protocol in an upcoming version I am currently implementing.
Author
Owner

@colinmorelli commented on GitHub (Nov 11, 2016):

Awesome - new apis for NSFetchedResultsController working great 👍

@colinmorelli commented on GitHub (Nov 11, 2016): Awesome - new apis for NSFetchedResultsController working great 👍
Author
Owner

@JohnEstropia commented on GitHub (Nov 15, 2016):

@colinmorelli Check out b230ed6400 (diff-dd90dc4a77a046f05e715c4c0ea209d2R40)
The FetchableSource and QueryableSource exposes

func internalContext() -> NSManagedObjectContext
@JohnEstropia commented on GitHub (Nov 15, 2016): @colinmorelli Check out https://github.com/JohnEstropia/CoreStore/commit/b230ed6400b2ca38533d597b9f514e0f0bfc7871#diff-dd90dc4a77a046f05e715c4c0ea209d2R40 The `FetchableSource` and `QueryableSource` exposes ``` swift func internalContext() -> NSManagedObjectContext ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#99