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

'No value or default value specified for property' error with defaultPropertyValues implemented #1371

Closed
frowing opened this issue Jan 21, 2015 · 3 comments
Assignees

Comments

@frowing
Copy link

frowing commented Jan 21, 2015

It seems like when adding an object in RLMAddObjectToRealm it doesn't use the defaultValues that exist in the schema to populate the properties. This is my model object:

@interface Place : RLMObject

@property (nonatomic, strong) NSString *guid;
@property (nonatomic, strong) NSString *title;

@end

@implementation Place

+ (NSString *)primaryKey
{
    return @"guid";
}

+ (NSDictionary *)defaultPropertyValues
{
    return @{@"guid" : @"", @"title" : @""};
}

@end

And this is how I create new object:

Place *place = [Place objectForPrimaryKey:guid];

if (!place)
{
    place = [[Place alloc] init];
}

place.guid = guid;
place.title = title;

[realm addObject:place];

@yoshyosh yoshyosh self-assigned this Jan 21, 2015
@yoshyosh
Copy link
Contributor

Hi @frowing you are setting place's values here:

place.guid = guid;
place.title = title;

So you are overriding the default property values. When guid or title is nil, this error is thrown. You will need to make sure you aren't passing in nil values into your place object

@amccarri
Copy link

amccarri commented Oct 7, 2015

@yoshyosh are you saying this is as designed?

@jpsim
Copy link
Contributor

jpsim commented Oct 7, 2015

@amccarri yes, setting a property to nil has a distinctly different meaning than not setting it at all once we officially release null support as described here: https://realm.io/news/realm-objc-swift-0.96.0-beta/

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 17, 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

No branches or pull requests

4 participants