NSDateFormatter 的 init 方法已被弃用?
根据
NSDateFormatter
的 init
方法是“适用于 iPhone OS 2.0 至 iPhone OS 3.2",因此不适用于 4.0。现在,它确实有效,但这看起来很奇怪。这是一个错误还是有其他方法来创建 NSDateFormatter ?
Per
The init
method of NSDateFormatter
is "Available in iPhone OS 2.0 through iPhone OS 3.2", and therefore not in 4.0. Now, it certainly works, but this seems odd. Is this is a mistake or is there some other way to create a NSDateFormatter
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
这次弃用只是苹果清理了 NSDateFormatter 的标头。 init 已在 NSNumberFormatter 继承的 NSObject 中声明。不需要重新声明,但是在实现中,苹果将覆盖 init,因为子类应该为超类的默认初始化程序提供实现。
This deprecation is just apple cleaning up the headers for NSDateFormatter. init is already declared in NSObject which NSNumberFormatter inherits from. Redeclaring is not necessary, however in the implementation apple will override init as subclassess should provide implementations for the default initializer of the superclass.
就像
falconcreek
所说这里,苹果只是清除文档。这意味着最初,
- (id) init
已在 NSDateFormatter 头文件中重新声明。这是不必要的,后来有人把它删除了。该文档可能是自动生成的,并且没有发现只是已弃用的重新声明。简而言之,随心所欲地使用
init
和NSDateFormatter
!Like
falconcreek
said here, Apple is just clearing the docs.That means that originally,
- (id) init
has been redeclared in the NSDateFormatter header file. That was unnecessary and somebody just removed it later. The documentation is probably generated automatically and didn't picked up that it was only the redecleration that was deprecated.In short, use
init
as you wish withNSDateFormatter
!我更相信头文件而不是文档。
例如, 格式化程序行为和操作系统版本似乎自相矛盾:
听起来
initWithDateFormat:allowNaturalLanguage:
实际上是已弃用的方法?I would trust the header files over the documentation.
For example, Formatter Behaviors and OS Versions seems to contradict itself:
It sounds like
initWithDateFormat:allowNaturalLanguage:
is actually the deprecated method?这真的很奇怪。也许
+[NSDateFormatter new]
可以完成这项工作?That’s really strange. Maybe
+[NSDateFormatter new]
will do the job?我在多个 iOS4 应用程序中使用 init 方法,并且它们已获得批准并在商店中。我想不出有什么办法让它工作,所以这看起来只是文档上的一个错字。
I use the init method in an multiple iOS4 apps and they are approved and in the store. I can think of no way to get it to work so it would seem like its just a typo on the docs.
类引用中的示例代码仍然使用
init
方法,因此我认为在您自己的代码中使用它是安全的。The example code in the class reference still uses the
init
method, so I'd say its safe to use it in your own code.您可以证明
NSDateFormatter
具有不同的行为,具体取决于您选择的初始化程序和您正在编译的 SDK。以下是使用SDK 10.5和10.6测试的。这将返回
NSDateFormatterBehavior10_0
。相反,当您使用
[[NSDateFormatter alloc] init];
时,行为是NSDateFormatterBehavior10_4
。You can proof yourself that
NSDateFormatter
has a different behaviour dependent on the initializer you choose and the SDK you are compiling with. The following is tested with SDK 10.5 and 10.6.This returns
NSDateFormatterBehavior10_0
.Instead, when you use
[[NSDateFormatter alloc] init];
the behaviour isNSDateFormatterBehavior10_4
.