gpt4 book ai didi

objective-c - NSDictionary 不区分大小写 objectForKey :

转载 作者:可可西里 更新时间:2023-11-01 03:04:54 25 4
gpt4 key购买 nike

NSDictionary 有 objectForKey 但它区分键的大小写。有没有功能可用,如

- (id)objectForKey:(id)aKey options:(id) options;

在选项中你可以传递“NSCaseInsensitiveSearch”

要从不区分大小写的 NSDictionary 中获取键,可以使用下面编写的以下代码。

最佳答案

您需要添加具有此功能的 NSDictionary 类的类别

- (id)objectForCaseInsensitiveKey:(NSString *)key {
NSArray *allKeys = [self allKeys];
for (NSString *str in allKeys) {
if ([key caseInsensitiveCompare:str] == NSOrderedSame) {
return [self objectForKey:str];
}
}
return nil;
}

关于objective-c - NSDictionary 不区分大小写 objectForKey :,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13607343/

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