mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-14 07:33:28 +01:00
ImportSource = CustomType.... possible? #101
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @DarrenAndes on GitHub (Nov 24, 2016).
I am trying to use the "importUniqueObjects" and I would like to use a custom type as the ImportSource, however everything but [String: AnyObject] gives me the "Value of type 'AsynchronousDataTransaction' has no member 'Element'" error.
I've even tried ImportSource = AnyObject (same error message)
Is there any way to use an ImportSource = CustomType so it is easier to access properties instead of source["id"] as? String inside "didInsertFromImportSource"
Is a custom object converted to a Dictionary the only acceptable solution? I am using ObjectMapper to do a lot of transforms to the JSON, however nested objects are not supported with the toJSON() function so it would be easier and more performant to pass around the actual Mappable type.
Thanks in advance.. really want to migrate to CoreStore (seems great), but this has me stuck.
@JohnEstropia commented on GitHub (Nov 24, 2016):
@DarrenAndes Have you checked https://github.com/JohnEstropia/CoreStore/issues/24 ?
There is no type constraint on
ImportSourceso you should be able to set it to any type you wish, but, how you callimportObjects(...)orimportUniqueObjects()matter. Those methods expect[ImportSource](array ofImportSource). Can you show how you are calling thetransaction.import*()methods?@DarrenAndes commented on GitHub (Nov 24, 2016):
@JohnEstropia thank you so much for your speedy response... Yes, I previously looked at #24 and it did provide some clarity into my problem.. I am now getting a different error now after moving all my code around (I used separate targets in my project) - 'ImportSource (aka BaseObjectMappableProtocol') is not a subtype of 'JobTierMappable'. However, error message are deceiving in Swift (sometime they are not clear on the real problem).
I have tried ImportSource = BaseObjectMappable and the way the code is below using a protocol and I get the same type of error message:
'Error 'ImportSource (aka BaseObjectMappableProtocol') is not a subtype of 'JobTierMappable'
Here is the simplified code which I am trying in Swift 2.3:
@JohnEstropia commented on GitHub (Nov 24, 2016):
@DarrenAndes What is
JobTierMappable? It looks like Swift is having a hard time casting it to[BaseObjectMappableProtocol].Can you show the declaration for the
JobTierMappabletype?@DarrenAndes commented on GitHub (Nov 24, 2016):
@JohnEstropia It is a subclass which eventually subclasses ObjectMapper's (Mappable) class
Sorry made a mistake in my own code, I'm back to the original error (AsynchronousDataTransaction' has no member 'Element).
Here is the correct func I was already passing an Array
@JohnEstropia commented on GitHub (Nov 24, 2016):
Try changing
to
@DarrenAndes commented on GitHub (Nov 25, 2016):
That code gives the error:
'ImportSource (aka BaseObjectMappableProtocol') is not a subtype of 'JobTierMappable'
I tried a long shot and made the conversion to [BaseObjectMappableProtocol] before passing into the func and that worked (it compiled)... Then there was a Swift casting issue. (fatal error: array cannot be bridged from Objective-C)... clearly the real cause of my problems.
I then did this extra step to help Swift along with the casting:
And it finally all worked... @JohnEstropia have wonderful Thanksgiving... I know I'm thankful for all your help and CoreStore itself (thanks for an excellent project)... It's replacing MagicalRecord :)
@JohnEstropia commented on GitHub (Nov 25, 2016):
Glad it worked out :)