Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash on non-@objc String? properties #5783

Merged
merged 2 commits into from
May 28, 2018
Merged

Conversation

tgoyne
Copy link
Member

@tgoyne tgoyne commented May 28, 2018

#5713 made it so that optional Swift properties of a supported data type (i.e. String? and object links) which do not have ivars due to not being declared as @objc dynamic would crash rather than merely fail to actually read and update the managed value when the property is used.

The idea behavior here would be to throw an error on schema initialization as it's an invalid model declaration, but that's a breaking change (as such objects do work correctly when unmanaged), so for now this just restores the pre-3.5.0 behavior.

Fixes #5781.

 #5713 made it so that optional Swift properties of a supported data type (i.e.
`String?` and object links) which do not have ivars due to not being declared
as `@objc dynamic` would crash rather than merely fail to actually read and
update the managed value when the property is used.

The idea behavior here would be to throw an error on schema initialization as
it's an invalid model declaration, but that's a breaking change (as such
objects do work correctly when unmanaged), so for now this just restores the
pre-3.5.0 behavior.
@tgoyne tgoyne self-assigned this May 28, 2018
@@ -90,17 +90,24 @@ void RLMInitializeSwiftAccessorGenerics(__unsafe_unretained RLMObjectBase *const
}

for (RLMProperty *prop in object->_objectSchema.swiftGenericProperties) {
id ivar = object_getIvar(object, prop.swiftIvar);
if (!ivar) {
// FIXME: this should actually be an error as it's the result of an
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there an issue tracking this, so we remember fixing it for the next major version?

@@ -123,6 +123,10 @@ - (void)doesNotRecognizeSelector:(SEL)aSelector {
}

id RLMGetOptional(__unsafe_unretained RLMOptionalBase *const self) {
if (!self) {
// FIXME: this should actually be an error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Link to issue.

@@ -132,6 +136,10 @@ id RLMGetOptional(__unsafe_unretained RLMOptionalBase *const self) {
}

void RLMSetOptional(__unsafe_unretained RLMOptionalBase *const self, __unsafe_unretained const id value) {
if (!self) {
// FIXME: this should actually be an error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above. Link to issue.

@tgoyne tgoyne merged commit b47b55b into master May 28, 2018
@tgoyne tgoyne deleted the tg/nonobjc-optional-string branch May 28, 2018 12:49
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Realm Crashing on Read/ Write operator bool() const
2 participants