iOS Migrations

127 views
Skip to first unread message

Oleg Anghelov

unread,
Mar 24, 2015, 9:24:28 AM3/24/15
to realm...@googlegroups.com
Hi!
I've start to play around with migrations in iOS.
What I noticed, is that we can set properties via key-value style, like in the documentation:

[migration enumerateObjects:Person.className block:^(RLMObject *oldObject, RLMObject *newObject) {

                             newObject[@"fullName"] = [NSString stringWithFormat:@"%@ %@",
                                                      oldObject
[@"firstName"],

                                                        oldObject[@"lastName"]];          


                          }];


Which is pretty cool.
But what I noticed, is that if we add a new property of a basic type (NSInteger, BOOL), it will not work. 

For instance:

@interface Person : RLMObject


@property BOOL isStuff;



It will obviously not work.
So the only solution would be to cast the `newObject` to `Person` class and explicitly set the property?

Person *newPerson = (Person *)newObject;
newPerson
= YES;

is it correct?


looking forward for your reply,
Kind regards,
Oleg.
Message has been deleted

Oleg Anghelov

unread,
Mar 24, 2015, 9:34:07 AM3/24/15
to realm...@googlegroups.com
*there should be
newPerson.isStuff = YES;

And I am afraid there is a problem with it. As I see the enumerated objects are not really object of the enumerated class, because on the code above I got

2015-03-24 15:27:17.278 RealmMigration[29256:5779790] -[RLMObject setIsStuff:]: unrecognized selector sent to instance 0x7fcaee07c1b0

2015-03-24 15:27:17.289 RealmMigration[29256:5779790] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RLMObject setIsStuff:]: unrecognized selector sent to instance 0x7fcaee07c1b0'


So the question is simple:

how to handle migrations of simple typed variables?

Samuel Giddins

unread,
Mar 24, 2015, 12:09:45 PM3/24/15
to Oleg Anghelov, realm...@googlegroups.com
Oleg,
Doing `newObject[@"isStuff"] = @YES` should do the trick!

--
Samuel Giddins



--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa unsub...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/c397ec09-58f8-4e8d-9699-89aa42048ea5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



On Tue, Mar 24, 2015 at 1:26 PM UTC, Oleg Anghelov <oleg.a...@gmail.com> wrote:
*there should be
newPerson.isStuff = YES;

--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa unsub...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/37dc594e-6eaa-43a6-9317-d5d671750ab0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
You received this message because you are subscribed to the Google Groups "Realm" group.
To unsubscribe from this group and stop receiving emails from it, send an email to realm-cocoa...@googlegroups.com.
To post to this group, send email to realm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/realm-cocoa/7629e7a3-45d4-4356-8abe-20147c23c6ab%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



{#HS:79659039-753#}

Oleg Anghelov

unread,
Mar 25, 2015, 5:01:14 AM3/25/15
to realm...@googlegroups.com, oleg.a...@gmail.com, he...@realm.io
Hi.
Did you try it?

I get

2015-03-25 10:56:23.576 RealmMigration[34299:6811640] *** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid property name'


Please take a look on this simple project:


Samuel Giddins

unread,
Mar 25, 2015, 2:34:06 PM3/25/15
to Oleg Anghelov, realm...@googlegroups.com
Oleg,
I'm unable to reproduce the exception you were seeing with the test project you shared.

--
Samuel Giddins



{#HS:79659039-753#}

Samuel Giddins

unread,
Apr 2, 2015, 6:01:50 PM4/2/15
to Oleg Anghelov, realm...@googlegroups.com
Oleg,
I just wanted to follow up with you to see if you've got everything working now?

--
Samuel Giddins



On Wed, Mar 25, 2015 at 6:33 PM UTC, Help <he...@realm.io> wrote:
Oleg,

I'm unable to reproduce the exception you were seeing with the test project you shared.

--
Samuel Giddins



On Wed, Mar 25, 2015 at 9:01 AM UTC, Oleg Anghelov <oleg.a...@gmail.com> wrote:
{#HS:79659039-753#}

Oleg Anghelov

unread,
Apr 3, 2015, 4:00:29 AM4/3/15
to realm...@googlegroups.com, oleg.a...@gmail.com, he...@realm.io
I redid all my tests, everything looks fine now. 
Actually, during last weak I got a much clearer understanding on how Realm works.

Thank you four your patience and for your time! 
I do appreciate that.

Best regards,
Oleg.

Samuel Giddins

unread,
Apr 3, 2015, 1:19:09 PM4/3/15
to Oleg Anghelov, realm...@googlegroups.com
I'm so glad to hear that everything is going well!

--
Samuel Giddins



On Thu, Apr 2, 2015 at 10:01 PM UTC, Help <he...@realm.io> wrote:
Oleg,
I just wanted to follow up with you to see if you've got everything working now?

--
Samuel Giddins



On Wed, Mar 25, 2015 at 6:33 PM UTC, Help <he...@realm.io> wrote:
Oleg,
I'm unable to reproduce the exception you were seeing with the test project you shared.

--
Samuel Giddins



On Wed, Mar 25, 2015 at 9:01 AM UTC, Oleg Anghelov <oleg.a...@gmail.com> wrote:
Hi.
Did you try it?

I get

2015-03-25 10:56:23.576 RealmMigration[34299:6811640] *** Terminating app due to uncaught exception 'RLMException', reason: 'Invalid property name'



Please take a look on this simple project:
https://www.dropbox.com/s/o5p1ns0ppitjafy/TestProject.zip?dl=0



On Tue, Mar 24, 2015 at 4:09 PM UTC, Help <he...@realm.io> wrote:
Oleg,
Doing `newObject[@"isStuff"] = @YES` should do the trick!

--
Samuel Giddins



{#HS:79659039-753#}

Andrew Lin

unread,
Jun 14, 2015, 2:53:48 AM6/14/15
to realm...@googlegroups.com, he...@realm.io
I'm getting the same error on an existing Realm db where I've added a Bool property:

@interface DiseaseEntity : RLMObject

@property NSString *name;

@property NSString *desc;

@property DiseaseEntityType type;

@property BOOL favorite; // new property
@end


When running the migration I'm setting the new bool value to false:

            [migration enumerateObjects:DiseaseEntity.className block:^(RLMObject *oldObject, RLMObject *newObject) {


                DiseaseEntity *newDe = (DiseaseEntity *)newObject;


                newDe.favorite = NO;

           }];


I get the following exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RLMDynamicObject setFavorite:]: unrecognized selector sent to instance 0x7fe963d246a0'


When opening the Realm in the Realm Browser, I also do not see the additional property on the class. 

I am using Realm 0.93.1. I haven't had any issues adding other properties previously. 

Thanks!

Andrew

Tim Oliver

unread,
Jun 15, 2015, 1:19:04 PM6/15/15
to Andrew Lin, realm...@googlegroups.com
Hi Andrew!

Thanks for your email!

I just went over the Realm migration sample code to confirm, and it looks like you can't actually bring your own RLMObject subclasses into the migration block.
Instead, you just reference the original RLMObject objects, and access the properties via the NSDictionary literal syntax.

Try this out in your code instead:


[migration enumerateObjects:DiseaseEntity.className block:^(RLMObject *oldObject, RLMObject *newObject) {
newObject[@"favourites"] = NO;
}];

Let me know if that helps!

Thanks!

-Tim

--
Tim Oliver




On Sun, Jun 14, 2015 at 6:54 AM UTC, Andrew Lin <arl...@gmail.com> wrote:
I'm getting the same error on an existing Realm db where I've added a Bool property:


@interface DiseaseEntity : RLMObject

@property NSString *name;

@property NSString *desc;

@property DiseaseEntityType type;

@property BOOL favorite; // new property@end



When running the migration I'm setting the new bool value to false:


 [migration enumerateObjects:DiseaseEntity.className block:^(RLMObject *oldObject, RLMObject *newObject) {


DiseaseEntity *newDe = (DiseaseEntity *)newObject;


newDe.favorite = NO;

}];



I get the following exception:


*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RLMDynamicObject setFavorite:]: unrecognized selector sent to instance 0x7fe963d246a0'



When opening the Realm in the Realm Browser, I also do not see the additional property on the class.

I am using Realm 0.93.1. I haven't had any issues adding other properties previously.

Thanks!

Andrew



{#HS:97681234-1316#}

Andrew Lin

unread,
Jun 16, 2015, 12:13:41 AM6/16/15
to realm...@googlegroups.com, he...@realm.io
I tried changing the code to reference the standard RLMObject using NSDictionary literal syntax: 

        [RLMRealm setSchemaVersion:13 forRealmAtPath:[RLMRealm defaultRealmPath] withMigrationBlock:^(RLMMigration *migration, uint64_t oldSchemaVersion) {


                [migration enumerateObjects:DiseaseEntity.className block:^(RLMObject *oldObject, RLMObject *newObject) {


                    newObject[@"favorite"] = NO;


                    NSLog(@"newObject: %@", newObject);

               }];

       }];


When running the migration script, I still get the following error on the assignment of the BOOL value:

Terminating app due to uncaught exception 'RLMException', reason: 'Invalid property name'


Any thoughts?
Reply all
Reply to author
Forward
0 new messages