领域检索特定数据 [英] Realm retrieving specific data
问题描述
美好的一天! 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;
}
如何获取所需的特定数据?例如,fName
和objectId
How can i get the specific data i want? For example, the fName
and objectId
感谢您的回答!更大的力量!
Thanks for your answers! More power!
推荐答案
RLMResults
与NSArray
有许多相似的方法,在某些情况下可以这样对待.例如,您可以使用-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屋!