gpt4 book ai didi

ios - NSDictionary访问仅一项

转载 作者:行者123 更新时间:2023-12-01 18:29:22 24 4
gpt4 key购买 nike

我有一个字典数组,字典中只有一个条目。

  ___       ___________
|___| --->|__|__|__|__| Array of Dictionary
|___| __|__
|___| |K|V| Dictionary
|___|

Array of Array


My dictionary content is <NSString*, UIImage*>

如何检索我的字典的值。

代码段:
for (int i=0 ; i< [imagesToFill count]; i++) {

NSDictionary* dict = [imagesToFill objectAtIndex:i];

UIImage* img = ??? [dict] // How to retrive value from above dict which has only 1 entry
NSString* imgPath = ???

}


Note: Each dict has <NSString*, UIImage*>

最佳答案

您可以像这样获得字典的所有键:

NSArray *allKeys = [dictionary allKeys];

当然,所有值都相同:
NSArray *allValues = [dictionary allValues];

然后只需使用 objectAtIndex:0(或 lastObject)来访问您的键或值。

两个数组的顺序都没有定义(即随机)。在您的情况下,这将不是问题。但是请记住这一点。

关于ios - NSDictionary访问仅一项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10473465/

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