Querying via managed object's context #80

Closed
opened 2025-12-29 15:23:48 +01:00 by adam · 2 comments
Owner

Originally created by @a13xb on GitHub (Sep 9, 2016).

It would be nice to be able to do a query through managed object's context, so you can filter and search object's relationships without having to pass a data stack explicitly or using the default global data stack.

For example:

class Post : NSManagedObject {
    @NSmanaged var comments: Set<Comment>
    var commentsByDate {
        managedObjectContext.fetchAll(...)
    }
    var commentsByVotes {
        managedObjectContext.fetchAll(...)
    }
}

But right now all querying methods on NSManagedObjectContext are marked as internal. Would you be open to making them public?

Originally created by @a13xb on GitHub (Sep 9, 2016). It would be nice to be able to do a query through managed object's context, so you can filter and search object's relationships without having to pass a data stack explicitly or using the default global data stack. For example: ``` swift class Post : NSManagedObject { @NSmanaged var comments: Set<Comment> var commentsByDate { managedObjectContext.fetchAll(...) } var commentsByVotes { managedObjectContext.fetchAll(...) } } ``` But right now all querying methods on `NSManagedObjectContext` are marked as internal. Would you be open to making them public?
adam added the enhancementfixed labels 2025-12-29 15:23:48 +01:00
adam closed this issue 2025-12-29 15:23:48 +01:00
Author
Owner

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

It was a conscious decision to not expose NSManagedObjectContext to ensure transaction integrity. I'll see if there's a way to take advantage of Swift 3's new private behavior so only transaction and datastack extensions can access NSManagedObjectContext's fetch methods

@JohnEstropia commented on GitHub (Sep 10, 2016): It was a conscious decision to not expose NSManagedObjectContext to ensure transaction integrity. I'll see if there's a way to take advantage of Swift 3's new `private` behavior so only transaction and datastack extensions can access NSManagedObjectContext's fetch methods
Author
Owner

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

This has been implemented in b230ed6400

See the new FetchableSource and QueryableSource protocols

@JohnEstropia commented on GitHub (Nov 21, 2016): This has been implemented in https://github.com/JohnEstropia/CoreStore/commit/b230ed6400b2ca38533d597b9f514e0f0bfc7871 See the new `FetchableSource` and `QueryableSource` protocols
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/CoreStore#80