在Xcode的Plist里search数组

我正在开发一个应用程序,该应用程序应该searchPlist数据中的string,并返回一个值,以提示用户是什么types的品牌。 例如,用户在我的文本字段中input“iPhone”,应用程序应该点击文本字段下方的“Go”button,返回用户input的产品品牌。

在我的Products.plist里面,它包含品牌的某些产品的品牌arrays。 例子是:

苹果:iPhone,iPod,iPad,Mac索尼:PSP,PS3,Bravia,Xperia三星:Galaxy S II,Galaxy S III,Galaxy Tab

我怎样才能做到这一点? 我已经做了我的应用程序工作正常,但没有使用plist。 我只想使用应用程序的Plist来轻松维护和更新。

考虑你的plist文件叫data.plist,这是你应该这样做的:

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