这是我现在如何获得货币符号的代码:
NSLocale *lcl = [[[NSLocale alloc] initWithLocaleIdentifier:@"au_AU"] autorelease];
NSNumberFormatter *fmtr = [[[NSNumberFormatter alloc] init] autorelease];
[fmtr setNumberStyle:NSNumberFormatterCurrencyStyle];
[fmtr setLocale:lcl];
NSLog( @"%@", [lcl displayNameForKey:NSLocaleCurrencySymbol value:@"AUD"] );
NSLog( @"%@", [fmtr currencySymbol] );
Run Code Online (Sandbox Code Playgroud)
两个NSLog都返回"AU $".正如我从Apple开发文档中所理解的那样,每种货币至少有两个货币符号(这些符号可能是相同的) - 本地(在一个国家内使用.例如澳大利亚的$)和国际货币符号(AU $)对于澳大利亚).所以,问题是如何获得LOCAL货币符号.有任何想法吗?
提前致谢.
我有一个A符合Equatable协议和实现==功能的类.在子类中,B我==用更多的检查覆盖.
但是,当我在两个实例数组B(两者都有类型Array<A>)之间进行比较时,调用==for A.当然,如果我改变两个阵列的类型Array<B>,==对于B被调用.
我提出了以下解决方案:
A.swift:
internal func ==(lhs: A, rhs: A) -> Bool {
if lhs is B && rhs is B {
return lhs as! B == rhs as! B
}
return ...
}
Run Code Online (Sandbox Code Playgroud)
这看起来很丑陋,必须扩展到每个子类A.有没有办法确保==首先调用子类?
我想用以下签名创建参数解析器:
./myapp [-a [-b BVAL] | -c]
换句话说,用户-b BVAL只有在提供参数的情况下才能提供参数-a.
这是很容易地创建互斥组-a和-c,但我无法弄清楚如何建立关系allow -b only if -a provided
item = [[NSMutableDictionary alloc] init];
[[self item] setObject:self.currentDay forKey:@"day"];
Run Code Online (Sandbox Code Playgroud)
这是iphone wat的代码,它在java中是等价的
iphone ×2
objective-c ×2
android ×1
argparse ×1
currency ×1
dictionary ×1
equality ×1
formatting ×1
java ×1
overriding ×1
python ×1
swift ×1