Originally created by @lucasiscovici on GitHub (Sep 24, 2016).
Hey someone have an idea please ? func fetch<T: NSManagedObject>(_ myconfig:String) -> [T] { return CoreStore.fetchAll(From<T>(myconfig)) }
Originally created by @lucasiscovici on GitHub (Sep 24, 2016).
Hey someone have an idea please ?
`
func fetch<T: NSManagedObject>(_ myconfig:String) -> [T] {
return CoreStore.fetchAll(From<T>(myconfig))
}
`
adam
added the question label 2025-12-29 15:23:59 +01:00
Hi, thank you for the feedback!
I'm not sure I understand your question. Are you proposing to add your method to CoreStore?
If so, CoreStore intentionally avoids shared methods like this because fetches can come from either the DataStack (readonly)
CoreStore.fetchAll(From<T>(myConfig))
or any transaction (readwrite).
transaction.fetchAll(From<T>(myConfig))
so sorry, any utility that abstracts away the datastack and the transaction is highly unlikely to be added to CoreStore.
If I misunderstood your question, please clarify.
@JohnEstropia commented on GitHub (Sep 27, 2016):
Hi, thank you for the feedback!
I'm not sure I understand your question. Are you proposing to add your method to CoreStore?
If so, CoreStore intentionally avoids shared methods like this because fetches can come from either the DataStack (readonly)
```
CoreStore.fetchAll(From<T>(myConfig))
```
or any transaction (readwrite).
```
transaction.fetchAll(From<T>(myConfig))
```
so sorry, any utility that abstracts away the datastack and the transaction is highly unlikely to be added to CoreStore.
If I misunderstood your question, please clarify.
BUT, the compiler cannot guarantee that your self.string has any relation with <T: NSManagedObject>. You want to design a generic function but your input (var string) are dynamic.
If you want to make CoreStoreHelper fully generic, you will have to make it generic
@JohnEstropia commented on GitHub (Sep 28, 2016):
You should be able to create a generic `From`:
``` swift
func fetch<T: NSManagedObject>() -> [T] {
let f = From<R>(NSClassFromString(self.string!), self.myconf)
return CoreStore.fetchAll(f)!
}
```
BUT, the compiler cannot guarantee that your `self.string` has any relation with `<T: NSManagedObject>`. You want to design a generic function but your input (`var string`) are dynamic.
If you want to make `CoreStoreHelper` fully generic, you will have to **make it generic**
```
class CoreStoreHelper<T: NSManagedObject> {
// ...
func fetch() -> [T] {
// ...
}
}
```
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 @lucasiscovici on GitHub (Sep 24, 2016).
Hey someone have an idea please ?
func fetch<T: NSManagedObject>(_ myconfig:String) -> [T] { return CoreStore.fetchAll(From<T>(myconfig)) }@JohnEstropia commented on GitHub (Sep 27, 2016):
Hi, thank you for the feedback!
I'm not sure I understand your question. Are you proposing to add your method to CoreStore?
If so, CoreStore intentionally avoids shared methods like this because fetches can come from either the DataStack (readonly)
or any transaction (readwrite).
so sorry, any utility that abstracts away the datastack and the transaction is highly unlikely to be added to CoreStore.
If I misunderstood your question, please clarify.
@lucasiscovici commented on GitHub (Sep 27, 2016):
Thanks for you answer!
i want to create an abstract class CoreStoreHelper
`
}
`
To help my NSManagedObject classes Helper
ex:
`
import Foundation
}
`
I succeed my generic fetch
i create From object
`
@JohnEstropia commented on GitHub (Sep 28, 2016):
You should be able to create a generic
From:BUT, the compiler cannot guarantee that your
self.stringhas any relation with<T: NSManagedObject>. You want to design a generic function but your input (var string) are dynamic.If you want to make
CoreStoreHelperfully generic, you will have to make it generic@JohnEstropia commented on GitHub (Sep 29, 2016):
I'll close this issue for now. If you have other questions feel free to continue the discussion :)