leo
leo

Reputation: 21

Add a property in realm the project is crash

In follow is my realm file:

@property NSString *operator;
@property NSString *publishTime;

Now I add a property, the realm file is becoming :

@property NSString *operator;
@property NSString *publishTime;
@property NSString *title;

then I run the project in Xcode, click the button where used realm, the project is crash. The errors is

File "/Users/ltl/Library/Application Support/Realm/rlm_lldb.py", line 226, 
in RLMResults_SummaryProvider if not is_results_evaluated(obj):
File "/Users/ltl/Library/Application Support/Realm/rlm_lldb.py",  line 213, 
in is_results_evaluated 
mode_query_value = next(m for m in mode_type.enum_members 
if m.name == 'Query').GetValueAsUnsigned() 
StopIteration

How can I fix it ?


But When I delete the APP from iPhone, run the project again, and click the button where used realm, the project is not crash, so I have no idea how to solve this issue? God, it is crash again!!!

Upvotes: 2

Views: 1062

Answers (1)

TiM
TiM

Reputation: 15991

When you modify the schema of a Realm object (i.e., add a new property), any existing Realm files that are using the old schema need to undergo a migration in order for them to be updated with the new property. In your case, since you're just adding a new field and not moving any data, you don't need to specify in the migration block, but it's still necessary to have:

RLMRealmConfiguration *config = [RLMRealmConfiguration defaultConfiguration];
config.schemaVersion = 1;
config.migrationBlock = ^(RLMMigration *migration, uint64_t oldSchemaVersion) { };
[RLMRealmConfiguration setDefaultConfiguration:config];

When you delete the app from the device, you're also deleting the Realm file inside it as well. When you rebuild it, you're deploying a new Realm file with the new schema, which is why it works after that.

Upvotes: 1

Related Questions