gpt4 book ai didi

ios - 从 Plist 搜索

转载 作者:行者123 更新时间:2023-11-28 18:35:05 26 4
gpt4 key购买 nike

有人能帮我吗

我在应用程序启动我的应用程序时加载了 plist 并且我有一个搜索输入。当我在输入中插入文本时,我想从 plist

中搜索
self.plistFile = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"xutbe"] ofType:@"plist"];
self.allData = [NSArray arrayWithContentsOfFile:self.plistFile];

我这样试过但是不行

NSString *INPUT = @"s";
self.plistFile = [[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"filename"] ofType:@"plist"];
self.allData = [NSArray arrayWithContentsOfFile:self.plistFile];

NSArray *searchRes = [self.allData filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self == %@", INPUT]];
NSLog(@"%@", searchRes);

也试过了,还是不行

NSString* plistPath = [[NSBundle mainBundle] pathForResource:@"xutbe" ofType:@"plist"]; NSDictionary* dict = [NSDictionary dictionaryWithContentsOfFile:plistPath]; NSDictionary* vcDict = [dict valueForKey:@"sd"]; NSLog(@"%@", vcDict);

最佳答案

如果你想从 NSArray 中搜索一个对象,使用 NSPredicate

NSArray *searchRes = [self.allData filteredArrayUsingPredicate:[NSPredicate
predicateWithFormat:@"self == %@", INPUT]];

关于ios - 从 Plist 搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20676877/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com