Originally created by @OlionCompany on GitHub (May 23, 2019).
How can I get all the unique attributes from an Entity?
E.g.:
EntityA = "a: String?, b: Int?, entityB: EntityB?"
EntityB = "a: String?, b: Int?"
My code:
let result = try self.dataStack.fetchAll(From<EntityA>()
.where(clauses)
.tweak {
$0.resultType = .dictionaryResultType
$0.propertiesToFetch = ["entityB"]
$0.returnsDistinctResults = true
})
fetchAll waits for [EntityA] and crash to return
Originally created by @OlionCompany on GitHub (May 23, 2019).
How can I get all the unique attributes from an Entity?
E.g.:
EntityA = "a: String?, b: Int?, entityB: EntityB?"
EntityB = "a: String?, b: Int?"
My code:
```
let result = try self.dataStack.fetchAll(From<EntityA>()
.where(clauses)
.tweak {
$0.resultType = .dictionaryResultType
$0.propertiesToFetch = ["entityB"]
$0.returnsDistinctResults = true
})
```
fetchAll waits for [EntityA] and crash to return
adam
added the question label 2025-12-29 18:25:12 +01:00
@JohnEstropia commented on GitHub (May 24, 2019):
You can use `queryAttributes(...)` for this. See https://github.com/JohnEstropia/CoreStore#querying (Specifically the entries on `queryAttributes(...)`)
I tried and it doesn't work
СoreStore can't do requests of the attributes with a check for uniqueness.
@OlionCompany commented on GitHub (May 24, 2019):
I tried and it doesn't work
СoreStore can't do requests of the attributes with a check for uniqueness.
so I assumed you were querying properties. Can you give a concrete example of data and what results you are after?
@JohnEstropia commented on GitHub (May 24, 2019):
Sorry, I'm not sure I understood your question then. Your example says
> E.g.:
> EntityA = "a: String?, b: Int?, entityB: EntityB?"
> EntityB = "a: String?, b: Int?"
so I assumed you were querying properties. Can you give a concrete example of data and what results you are after?
This question can be closed, I think I figured it out.
If you're trying to extract query attribute from EntityA as other CoreData Entity -> result: Array of [String : NSManagedObjectID].
After conversion we need to fetch entities for this ids. Example:
In Tweak we can add { $0.resultType = .managedObjectResultType }) for fetch Entities instead Ids, but, app crashes.
@OlionCompany commented on GitHub (May 29, 2019):
This question can be closed, I think I figured it out.
If you're trying to extract query attribute from EntityA as other CoreData Entity -> result: Array of [String : NSManagedObjectID].
After conversion we need to fetch entities for this ids. Example:
```
let values = try self.dataStack.queryAttributes(From<EntityA>(),
Select(#keyPath(EntityA.entityB)),
Where(\.entityB != nil && ...),
GroupBy(\EntityA.entityB),
OrderBy(.ascending(\EntityA.entityB?.name)),
Tweak { $0.returnsDistinctResults = true })
let ids: [NSManagedObjectID] = values.compactMap { $0.first?.value as? NSManagedObjectID }
let result: [EntityB] = self.dataStack.fetchExisting(ids)
```
In Tweak we can add { $0.resultType = .managedObjectResultType }) for fetch Entities instead Ids, but, app crashes.
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 @OlionCompany on GitHub (May 23, 2019).
How can I get all the unique attributes from an Entity?
E.g.:
EntityA = "a: String?, b: Int?, entityB: EntityB?"
EntityB = "a: String?, b: Int?"
My code:
fetchAll waits for [EntityA] and crash to return
@JohnEstropia commented on GitHub (May 24, 2019):
You can use
queryAttributes(...)for this. See https://github.com/JohnEstropia/CoreStore#querying (Specifically the entries onqueryAttributes(...))@OlionCompany commented on GitHub (May 24, 2019):
I tried and it doesn't work
СoreStore can't do requests of the attributes with a check for uniqueness.
@JohnEstropia commented on GitHub (May 24, 2019):
Sorry, I'm not sure I understood your question then. Your example says
so I assumed you were querying properties. Can you give a concrete example of data and what results you are after?
@OlionCompany commented on GitHub (May 29, 2019):
This question can be closed, I think I figured it out.
If you're trying to extract query attribute from EntityA as other CoreData Entity -> result: Array of [String : NSManagedObjectID].
After conversion we need to fetch entities for this ids. Example:
In Tweak we can add { $0.resultType = .managedObjectResultType }) for fetch Entities instead Ids, but, app crashes.