领域检索特定数据 [英] Realm retrieving specific data

查看:106
本文介绍了领域检索特定数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

美好的一天! 3天前,我开始使用iOS的Realm.io数据库.我可以将数据从应用程序存储到数据库中.但是检索它让我头疼.我的问题是我无法选择数据库上的特定数据.我正在使用它来获取数据

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);

现在结果:

2015-05-07 05:31:01.554 Sample App[2401:79922] MapLocationCoordinates {
    objectId = k0zpFLr5Un;
    fName = George;
    fLatitude = 11.985050;
    fLongitude = 121.925295;
}

如何获取所需的特定数据?例如,fNameobjectId

How can i get the specific data i want? For example, the fName and objectId

感谢您的回答!更大的力量!

Thanks for your answers! More power!

推荐答案

RLMResultsNSArray有许多相似的方法,在某些情况下可以这样对待.例如,您可以使用-firstObject方法获取RLMResults中的第一个对象.

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.

在您的代码中:

MapLocationCoordinates *coords = [data firstObject];
NSString *fName = [coords fName];
NSString *objectId = [coords objectId];

您还可以使用与for(id obj in collection){}数组相同的方式遍历RLMResults集合.

You can also iterate over an RLMResults collection in the same way as you would an array with for(id obj in collection){}.

这篇关于领域检索特定数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆