什么是 __AVAILABILITY_INTERNAL__IPHONE_2、NS_AVAILABLE ?尝试使用 NSNumberFormatter,返回 (null)
我在让 NSNumberFormatter 正常工作时遇到了一些麻烦。
我正在使用 Three20 Framework 在 iOS4 中进行编译。
所有 NSNumberFormatter 选择器都需要名为 NS_AVAILABLE 的东西作为选择器上的第二个参数:
[numberFormatter setCurrencyGroupingSeparator:(NSString *)string __AVAILABILITY_INTERNAL__IPHONE_2:(int)_0];
我不确定我应该如何处理第二个参数。我已经尝试过:
[numberFormatter setCurrencyGroupingSeparator:@"," __AVAILABILITY_INTERNAL__IPHONE_2:2]; // Warning: NSNumberFormatter' may not respond to '-setCurrencyGroupingSeparator:__AVAILABILITY_INTERNAL__IPHONE_2:
[numberFormatter setCurrencyGroupingSeparator:@"," __AVAILABILITY_INTERNAL__IPHONE_2:2_0]; //Error: invalid suffix "_0" on integer constant
以及更多的迭代。
如果我不指定 __AVAILABLE_INTERNAL__IPHONE_2 它不会抛出警告并且编译正常,但选择器文本是黑色的,而不是 Xcode 中的深紫色,就好像它无法识别一样。
这是完整的代码片段:
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setCurrencyGroupingSeparator:@","];
[numberFormatter setUsesGroupingSeparator:YES];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
numberString = [NSString stringWithFormat: @"$%@",[numberFormatter stringFromNumber:myNsNumber]]; // myNsNumber is an NSNumber with a value of 10000000
NSLog(@"numberString: %@",numberString); // numberString: (null) | instead of numberString: $10,000,000
我在 Google 上搜索了 _AVAILABILITY_INTERNAL__IPHONE_2 和 NS_AVAILABLE,但没有成功。
搜索developer.apple.com 只给我提供了iOS 4.0 API 差异。
这是 Three20 的问题吗?有谁知道这里发生了什么或者 NS_AVAILABLE 是什么?
I've been having some trouble getting NSNumberFormatter to work properly.
I'm compiling in iOS4 with the Three20 Framework.
All of the NSNumberFormatter selectors require something called NS_AVAILABLE as a second parameter on the selector:
[numberFormatter setCurrencyGroupingSeparator:(NSString *)string __AVAILABILITY_INTERNAL__IPHONE_2:(int)_0];
I'm not sure what I'm supposed to do with the second parameter. I've tried:
[numberFormatter setCurrencyGroupingSeparator:@"," __AVAILABILITY_INTERNAL__IPHONE_2:2]; // Warning: NSNumberFormatter' may not respond to '-setCurrencyGroupingSeparator:__AVAILABILITY_INTERNAL__IPHONE_2:
[numberFormatter setCurrencyGroupingSeparator:@"," __AVAILABILITY_INTERNAL__IPHONE_2:2_0]; //Error: invalid suffix "_0" on integer constant
and several more iterations of that.
If I don't specify the __AVAILABLE_INTERNAL__IPHONE_2 it doesn't throw a warning and compiles fine, but the selector text is black, not dark purple in Xcode as if it's not recognized.
Here's the full code snippet:
NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
[numberFormatter setCurrencyGroupingSeparator:@","];
[numberFormatter setUsesGroupingSeparator:YES];
[numberFormatter setNumberStyle:NSNumberFormatterCurrencyStyle];
numberString = [NSString stringWithFormat: @"$%@",[numberFormatter stringFromNumber:myNsNumber]]; // myNsNumber is an NSNumber with a value of 10000000
NSLog(@"numberString: %@",numberString); // numberString: (null) | instead of numberString: $10,000,000
I've Googled _AVAILABILITY_INTERNAL__IPHONE_2 and NS_AVAILABLE with no luck.
Searching developer.apple.com only gives me the iOS 4.0 API Diffs.
Is this an issue with Three20? Does anyone know whats going on here or what NS_AVAILABLE is all about?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
忘记到目前为止您在这篇文章中所拥有的一切。可用性信息让您知道这些方法包含在哪个 SDK 中。
这是有效的
NSNumberFormatter
代码。如果你有一个空字符串,那么要么是因为你的 NSNumber 是 null 或 NaN,要么是你的格式搞砸了。
Forget about just about everything you have in this post so far. The availability stuff lets you know what SDK the methods are included in.
This is working
NSNumberFormatter
code.If you have a null string, then it is either because your NSNumber is null or NaN, or your format is screwed up.