mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-01-11 20:00:30 +01:00
'Bundle' does not conform to expected element type 'SchemaMappingProvider' #252
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 @iby on GitHub (Jan 10, 2019).
The Local Store Setting Up example suggests:
But apparently
Bundleis not (no longer?) compatible withSchemaMappingProvider.@JohnEstropia commented on GitHub (Jan 10, 2019):
I've probably missed updating a documentation somewhere.
If your .xcmappingmodel files are within the
Bundle, you can omit themigrationMappingProvidersargument altogether.You can also use
InferredSchemaMappingProviderto be explicit (but this will always be the fallback regardless, or you can also useXcodeSchemaMappingProviderif you need to set specifically whichBundleto load .xcmappingmodel from for each target version.@iby commented on GitHub (Jan 10, 2019):
Great! I thought it might be the case. For some reason it fails doesn't discover mapping models in non-main bundle, though my data stack explicitly provides the bundle. Looks like data stack uses the explicit bundle for schema models, but not for mapping models. Can this be the case? Adding mapping models into the main bundle fixes it, or using explicit
XcodeSchemaMappingProvider, which is a little painful.@iby commented on GitHub (Jan 10, 2019):
Ignore this for now, there's something odd going on with the build cache. Will retest and confirm or close. 👍
@JohnEstropia commented on GitHub (Jan 10, 2019):
Yes, they do load from bundles separately as schema models are per-stack, and mapping models are per-store (you can have different mapping models for different files, for example).
That said,
InferredSchemaMappingProviderwill always be used as a fallback if no other mappings are found. And if you check the source code ofInferredSchemaMappingProvideryou'll find that it loadsNSMappingModels fromBundle.allBundles.Let me know if you resolve the issue on your side
@iby commented on GitHub (Jan 10, 2019):
No, all looks good, must have overlooked something. Thanks for looking into this!
@iby commented on GitHub (Jan 10, 2019):
I figured out the earlier issue, might be helpful for others who want to store models along with code in a separate framework. That framework might not be present in
Bundle.allBundleswhenInferredSchemaMappingProvidersearches for mappings, so the only workaround is to explicitly provide it withXcodeSchemaMappingProvider.It seems the
DataStackdoesn't store the bundle reference, but it would be very useful to pass it along intoInferredSchemaMappingProviderwhen needed to explicitly be search first instead of going through all bundles. Alternatively searchingBundle.allFrameworkswould solve this issue, but would add a potentially huge overhead.@JohnEstropia commented on GitHub (Jan 11, 2019):
Glad the issue was sorted out :)
Bundles being set separately for the DataStack and the SQLiteStore is by design. The DataStack's model is based on the newest schema, while the LocalStorage's model is based on the user's current version (which may be any version since the app's first release). That said, I should explain this better in the source documentation for
DataStack.init'sbundleargument.The overhead would be relatively fine (you are already doing a migration anyway). The issue with using
Bundle.allFrameworksby default is more about security. You wouldn't want a model to be accidentally loaded from a compromised 3rd party library.I'll close this issue as it looks like things are behaving as they were intended to. I would update the docs and maybe provide more helpful error logs when models cannot be found.