The Realm migration example on the Realm documentation site shows an example with a new NSString object. The example is simple and well explained.
if (oldSchemaVersion < 2) {
newObject[@"email"] = @""; // creates an NSString object...
}
But what about objects other than NSString? How does the code snippet need to be adapted in order to create objects of these other data types?
NSDateNSDataRLMArrayNSInteger,intdouble,float,CGFloatlongbool,BOOL
Only certain types of object in ObjC/Cocoa have a literal shortcut like this. (Historically,
NSStringwas in fact the sole class with such syntax, but several were added recently-ish by the Clang compiler.)There is no literal syntax for
NSDate,NSData, orRLMArray; these need to be created with an appropriate construction method.Primitive types like
double,long, andBOOLcannot be stored directly in anNSDictionary, but they can be wrapped up using the "sugar"@(), i.e.:This puts the value into an
NSNumberinstance, which then needs to be unwrapped to retrieve the primitive value: