Realm retrieving specific data

亡梦爱人 提交于 2019-12-24 14:21:49

问题


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!


回答1:


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){}.



来源:https://stackoverflow.com/questions/30098613/realm-retrieving-specific-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!