从方法返回后NSDATE NIL



我有一个简单的方法,可以从" 2017年11月"之类的字符串中确定nsdate。当我逐步介绍该方法时,实际日期具有正确的值,但零会传递给调用方法。

下面的代码一直在工作,直到最近,我正在XCode 9.0定位iOS 10/11。

这是调用方法

NSDate *eventDate = [DateClass dateFromMonthYearString:@"NOV 2017"];

方法定义

+(NSDate*)dateFromMonthYearString:(NSString*)monthYearString
{
    NSDateFormatter *formatter = [self cachedFormatter];
    [formatter setDateFormat:MONTH_YEAR_DATE_FORMAT];
    NSDate* actualDate = [formatter dateFromString:monthYearString];
    return actualDate;
}
+(NSDateFormatter*) cachedFormatter
{
    if (cachedDateFormatter == nil)
    {
        cachedDateFormatter = [[NSDateFormatter alloc] init];
        cachedDateFormatter.locale = [NSLocale currentAppLocale];
    }
    return cachedDateFormatter;
}

月_year_date_format定义为...

NSString * const MONTH_YEAR_DATE_FORMAT = @"MMM yyyy";

当我在方法定义中打印日期对象时,xcode正确打印了日期。当我尝试在方法定义之外" po"时,我只会得到类似的东西

(lldb) po eventDate
0x000000012eb048e0

有什么想法?

因此,当我通过nslog将值打印到控制台时,它会打印正确的值。看起来它只是变量显示和" po"命令在x9.1奇怪的??

中无法正常工作。

最新更新