NSDate initWithString

后端 未结 3 1209
半阙折子戏
半阙折子戏 2021-01-21 16:43

After updating Xcode to version 4.2 I received the following warning in my current project:

warning: \'NSDate\' may not respond to \'initWithString:\'

相关标签:
3条回答
  • 2021-01-21 17:24

    You should use NSDateFormatter to get an NSDate object from a string. This will give you more flexibility with the format of the input string.

    NSDateFormatter Reference

    0 讨论(0)
  • 2021-01-21 17:40

    This method is in the documentation only noted at the Mac OSX page, not the iOS. Why Apple has different versions is unclear to me, but they luckily respond the same.

    Because the class reference for iOS says there is no such method for iOS NSDate, you get the warning. Your code, however, will respond perfectly fine.

    To silence the warning, you should indeed use NSDateFormatter.

    Regards,

    Jacco

    0 讨论(0)
  • 2021-01-21 17:46

    Read the changes at this website http://developer.apple.com/library/ios/#releasenotes/General/iOS42APIDiffs/index.html Sometimes they change little syntax things and make newer and better ways of doing things.

    0 讨论(0)
提交回复
热议问题