Originally created by @minuscorp on GitHub (Feb 18, 2016).
I'd like to know if its possible given a query object with some properties: let object = CoreStore... I can update it self through the ImportableObject protocol, which has the mapping for the JSON but to a certain already saved object (several backends gives the primary key in respose after you upload a local created object to the backend).
Also, is there a way to export an object to [String: AnyObject] that also encodes their relationships?
Thank you! Grat job with this repo! 👍
Originally created by @minuscorp on GitHub (Feb 18, 2016).
I'd like to know if its possible given a query object with some properties: `let object = CoreStore...` I can update it self through the `ImportableObject` protocol, which has the mapping for the JSON but to a certain already saved object (several backends gives the primary key in respose after you upload a local created object to the backend).
Also, is there a way to export an object to [String: AnyObject] that also encodes their relationships?
Thank you! Grat job with this repo! :+1:
adam
added the question label 2025-12-29 15:22:52 +01:00
It might be more convenient to let the transaction have a method for this though. Feel free to post a github issue for the feature request.
is there a way to export an object to [String: AnyObject] that also encodes their relationships?
The ImportableObject and ImportableUniqueObject protocol methods accept a transaction argument for this very purpose. You can fetch and import from within those methods:
@JohnEstropia commented on GitHub (Feb 19, 2016):
You can call the `ImportableObject` methods directly if you want to:
``` swift
CoreStore.beginAsynchronous { transaction in
if let object = transaction.fetchOne(From(...), Where(...))
where object.shouldInsertFromImportSource(json, inTransaction: transaction) {
_ = try? object.didInsertFromImportSource(json, inTransaction: transaction)
}
transaction.commit { ... }
}
```
It might be more convenient to let the transaction have a method for this though. Feel free to post a github issue for the feature request.
> is there a way to export an object to [String: AnyObject] that also encodes their relationships?
The `ImportableObject` and `ImportableUniqueObject` protocol methods accept a `transaction` argument for this very purpose. You can fetch and import from within those methods:
``` swift
func didInsertFromImportSource(source: ImportSource, inTransaction transaction: BaseDataTransaction) throws {
self.attribute1 = source["key1"] as? String
self.attribute2 = source["key2"] as? NSNumber
self.relatedObject = try! transaction.importObject(
Into(RelatedObjectEntity),
source: source["relatedObjectKey"] as? RelatedObjectEntity.ImportSource
)
}
```
With the second question I meant if there's a method to export an object to JSON format (a simple [String: AnyObject] that follows the same rules as the exposed in the ImportableObject protocol but in the inverse path)
@minuscorp commented on GitHub (Feb 19, 2016):
With the second question I meant if there's a method to export an object to JSON format (a simple `[String: AnyObject]` that follows the same rules as the exposed in the `ImportableObject` protocol but in the inverse path)
@minuscorp Oh sorry.. For some reason I read that wrong.
I think it's not in CoreStore's scope to implement export utilities. In the end it would end up as a floating protocol that is used nowhere else in CoreStore. I suggest you just implement it directly on your NSManagedObject subclass, or write an extension that uses your app's mapping rules.
@JohnEstropia commented on GitHub (Feb 19, 2016):
@minuscorp Oh sorry.. For some reason I read that wrong.
I think it's not in CoreStore's scope to implement export utilities. In the end it would end up as a floating protocol that is used nowhere else in CoreStore. I suggest you just implement it directly on your NSManagedObject subclass, or write an extension that uses your app's mapping rules.
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 @minuscorp on GitHub (Feb 18, 2016).
I'd like to know if its possible given a query object with some properties:
let object = CoreStore...I can update it self through theImportableObjectprotocol, which has the mapping for the JSON but to a certain already saved object (several backends gives the primary key in respose after you upload a local created object to the backend).Also, is there a way to export an object to [String: AnyObject] that also encodes their relationships?
Thank you! Grat job with this repo! 👍
@JohnEstropia commented on GitHub (Feb 19, 2016):
You can call the
ImportableObjectmethods directly if you want to:It might be more convenient to let the transaction have a method for this though. Feel free to post a github issue for the feature request.
The
ImportableObjectandImportableUniqueObjectprotocol methods accept atransactionargument for this very purpose. You can fetch and import from within those methods:@minuscorp commented on GitHub (Feb 19, 2016):
With the second question I meant if there's a method to export an object to JSON format (a simple
[String: AnyObject]that follows the same rules as the exposed in theImportableObjectprotocol but in the inverse path)@JohnEstropia commented on GitHub (Feb 19, 2016):
@minuscorp Oh sorry.. For some reason I read that wrong.
I think it's not in CoreStore's scope to implement export utilities. In the end it would end up as a floating protocol that is used nowhere else in CoreStore. I suggest you just implement it directly on your NSManagedObject subclass, or write an extension that uses your app's mapping rules.
@JohnEstropia commented on GitHub (Feb 20, 2016):
Closing this issue for now. If you have further questions feel free to message anytime :)