Reputation: 229
Good Day! I started using Realm.io Database for iOS 3 days ago. I can store data from the app to the database. But Retrieving it gives me headache. My problem is i cannot select specific data on database. I'm using this to get the data
RLMResults *data = [MapLocationCoordinates allObjects];
NSString *rawData = [NSString stringWithFormat:@"%@",[data objectAtIndex:0]];
NSLog(@"%@",rawData);
Now the result:
2015-05-07 05:31:01.554 Sample App[2401:79922] MapLocationCoordinates {
objectId = k0zpFLr5Un;
fName = George;
fLatitude = 11.985050;
fLongitude = 121.925295;
}
How can i get the specific data i want? For example, the fName
and objectId
Thanks for your answers! More power!
Upvotes: 1
Views: 679
Reputation: 58458
RLMResults
has many similar methods as NSArray
and in some cases can be treated as such. For example, you can get the first object in the RLMResults
using the -firstObject
method.
In your code:
MapLocationCoordinates *coords = [data firstObject];
NSString *fName = [coords fName];
NSString *objectId = [coords objectId];
You can also iterate over an RLMResults
collection in the same way as you would an array with for(id obj in collection){}
.
Upvotes: 3