什么是 __AVAILABILITY_INTERNAL__IPHONE_2、NS_AVAILABLE ?尝试使用 NSNumberFormatter,返回 (null)

发布于 2024-09-29 02:31:04 字数 1583 浏览 5 评论 0原文

我在让 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_2NS_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

后来的我们 2024-10-06 02:31:04

忘记到目前为止您在这篇文章中所拥有的一切。可用性信息让您知道这些方法包含在哪个 SDK 中。

这是有效的 NSNumberFormatter 代码。

NSNumber *number = [UINumber numberWithInt:42];
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setFormatterBehavior:NSNumberFormatterBehavior10_4];
[nf setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *string = [nf stringFromNumber:number];
[nf release];

如果你有一个空字符串,那么要么是因为你的 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.

NSNumber *number = [UINumber numberWithInt:42];
NSNumberFormatter *nf = [[NSNumberFormatter alloc] init];
[nf setFormatterBehavior:NSNumberFormatterBehavior10_4];
[nf setNumberStyle:NSNumberFormatterDecimalStyle];
NSString *string = [nf stringFromNumber:number];
[nf release];

If you have a null string, then it is either because your NSNumber is null or NaN, or your format is screwed up.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文