搜索与第X code里面的plist阵列 [英] Search on Arrays inside Plist in Xcode
问题描述
我开发一个应用程序,应搜索中的plist数据中一个字符串,返回应及时什么样的用户价值,说品牌是。例如,在我的文本字段用户输入iPhone和应用程序应退回产品的品牌敲击下面的文本字段Go按钮后,输入用户。
I'm developing an app that should search a string inside the Plist data and return a value that should prompt the user what kind of, say brand it is. For example, the user inputs "iPhone" in my text field and the app should return the brand of the product the user inputted after tapping the Go button below the text field.
在我的Products.plist,它包含了与品牌有一定品牌的产品阵列。例子是:
Inside my Products.plist, It contains arrays of brands with certain products that brand has. Example would be:
苹果:iPhone的iPod,iPad的苹果
索尼:PSP,PS3,Bravia液晶,的Xperia
三星:银河S II,银河S III,Galaxy Tab的
Apple: iPhone, iPod, iPad, Mac Sony: PSP, PS3, Bravia, Xperia Samsung: Galaxy S II, Galaxy S III, Galaxy Tab
我怎样才能做到这一点?我已经做了我的应用程序工作正常,但没有使用的plist。我只想用一个PLIST的应用程序可以很容易地维护和更新。
How can I do this? I have already done my app working fine but without using a plist. I just want to use a Plist for the app to be easily maintained and updated.
推荐答案
考虑您的plist文件被称为data.plist,这是你应该怎么做的:
Consider your plist file is called data.plist, this is how you should do this:
NSBundle *bundle = [NSBundle mainBundle];
NSString *pListpath = [bundle pathForResource:@"data" ofType:@"plist"];
NSDictionary *dictionary = [[NSDictionary alloc] initWithContentsOfFile:pListpath];
for (NSString* key in [dictionary allKeys]){
NSArray *array = [dictionary objectForKey:key];
for (int j = 0; j < [array count]; j++) {
if ([[array objectAtIndex:j] isEqualToString:@"iPhone"]) {
NSLog(@"%@",key);
}
}
}
这篇关于搜索与第X code里面的plist阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!