可能的重复:
NSDate initWithString https://stackoverflow.com/questions/7770257/nsdate-initwithstring
我写了下面一行代码:
[[NSDate alloc] initWithString:@"2013-03-24 10:45:32 +0200"];
当我尝试编译时,出现以下错误消息:
ARC 语义问题:
'NSDate' 没有可见的 @interface 声明选择器 'initWithString:'
项目中包括以下内容:
#import <Foundation/Foundation.h>
为了确保包含该类,我尝试了以下行,该行编译没有问题:
[[NSDate alloc] init];
我的代码有什么问题吗?
XCode 版本 4.6。
iOS 6.1 项目中的基础 SDK。
iOS 平台的 NSDate 类中不存在 initWithString 函数,因为您需要首先使用 NSDateFormatter 指定日期格式化程序,该格式化程序将日期和时间的文本表示转换为 NSDate 对象。使用这样的东西:
NSString *currentDateString = @"2013-03-24 10:45:32";
NSDateFormatter *dateFormater = [[NSDateFormatter alloc] init];
[dateFormater setDateFormat:@"yyyy-MM-DD HH:mm:ss"];
NSDate *currentDate = [dateFormater dateFromString:currentDateString];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)