[ObjectSchema] Expose objectClass from RLMObjectSchema private interface #6244
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This change proposes the addition of the computed variable
public var objectClass: AnyClass { get }
onObjectSchema
to expose the underlyingRLMObjectSchema
's privateobjectClass
.Motivation
When working with Swift models, realm-cocoa will 'demangle' the original class name when building the shared schema. As a result, no mechanism exists for looking up the associated class type from a Realms schema. This isn't something that most people will need to do, but it can be really beneficial in cases where we might need to store some additional information on model definitions that needs to be validated either at runtime or in unit tests.
Although the
objectClass
is private onRLMObjectSchema
, a similar capability is possible in projects that use realm-cocoa directly since they'd be able to useNSClassFromString(objectSchema.className)
however this will returnnil
in Swift usingobjectSchema.className
since the value has been passed through+[RLMSwiftSupport demangleClassName:]
I hope there is no problem with such change, my inspiration for the change was that I noticed
Realm.Configuration
is actually doing a similar thing in order to expose theobjectTypes
getter since they're backed by a customRLMSchema
but I wanted similar functionality when reading object schemas from a Realm directly