gpt4 book ai didi

ios - 之间的区别 – displayNameForKey :value: and - objectForKey: in NSLocale Class

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

您好,只是一个简单的问题,在 NSLocale 类中 – displayNameForKey:value: 和 – objectForKey: 之间有什么区别?我在网上搜索但没有得到它。谢谢。

Apple Document

displayNameForKey:value:
Returns the display name for the given value.

- (NSString *)displayNameForKey:(id)key value:(id)value
Parameters
key
Specifies which of the locale property keys value is (see “Constants”),
value
A value for key.
Return Value
The display name for value.



objectForKey:
Returns the object corresponding to the specified key.

- (id)objectForKey:(id)key
Parameters
key
The key for which to return the corresponding value. For valid values of key, see “Constants.”
Return Value
The object corresponding to key.

最佳答案

您使用 displayNameForKey:value: 来根据您调用的语言环境对象获取适合显示的标签。例如:

NSLocale *french = [[[NSLocale alloc] initWithLocaleIdentifier:@"fr_FR"] autorelease];
NSString *frenchName = [french displayNameForKey:NSLocaleIdentifier value:@"fr_FR"];

NSLocale *english = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] autorelease];
NSString *englishName = [english displayNameForKey:NSLocaleIdentifier value:@"fr_FR"];

NSLog(@"French locale in French is called '%@'", frenchName);
NSLog(@"French locale in English is called '%@'", englishName);

将产生输出:

法语中的法语区域称为“français(法国)”
法语语言环境在英语中称为“法语(法国)”

NSLocale Class Reference 中有大量示例.

关于ios - 之间的区别 – displayNameForKey :value: and - objectForKey: in NSLocale Class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10869358/

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