2015-01-09 3 views
0

NSCalendar 인스턴스에 calendarIdentifier 메시지를 보내려고합니다. 왜 내가 널 얻고(OBJ C) NSCalendar 인스턴스에 calendarIdentifier 메시지를 보내고 null을 수신합니다.

2015-01-08 19:12:26.651 TimeAfterTime[1325:40863] This NSDate Object lives at 0x10010fe70 
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] The date now is 2015-01-09 00:12:26 +0000 
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] Seconds since 1970: 1420762346.651615 
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] The date after 100,000 seconds 
from 2015-01-09 00:12:26 +0000 is : 2015-01-10 03:59:06 +0000 
2015-01-08 19:12:26.656 TimeAfterTime[1325:40863] My calender is (null) 
Program ended with exit code: 0 

:

#import <Foundation/Foundation.h> 

int main(int argc, const char * argv[]) { 

//Create a date instance. 
NSDate *now = [NSDate date]; 
NSLog(@"This NSDate Object lives at %p", now); 
NSLog(@"The date now is %@",now); 

//Seconds from the date instance and 1970. 
NSTimeInterval seconds_since_1970 = [now timeIntervalSince1970]; 
NSLog(@"Seconds since 1970: %f", seconds_since_1970); 

//Future date from date instance. 
NSDate *later = [now dateByAddingTimeInterval:100000]; 
NSLog(@"The date after 100,000 seconds from %@ is : %@", now, later); 

//Create calender instance with user settings. 
NSCalendar *cal = [[NSCalendar alloc] init]; 
NSString *calenderIdentity = [cal calendarIdentifier]; 
NSLog(@"My calender is %@", calenderIdentity); 



return 0; 
} 

그러나, 어떤 이유로 나는 콘솔에서 반환으로이 얻을 : 이 내 코드? 나는 주변을 둘러 보았지만 아무 것도 찾을 수없는 것 같습니다.

덕분에,

답변

0

당신은 initWithCalendarIdentifier: 이니셜로 알려진 일정 유형을 제공해야합니다. 문자열을 제공하는 것만으로는 효과가 없습니다. 알려진 유형은 다음과 같습니다.

NSGregorianCalendar 
NSBuddhistCalendar 
NSChineseCalendar 
NSHebrewCalendar 
NSIslamicCalendar 
NSIslamicCivilCalendar 
NSJapaneseCalendar 
NSRepublicOfChinaCalendar 
NSPersianCalendar 
NSIndianCalendar 
NSISO8601Calendar 

이렇게하면 identifier: 메시지에 대해 널 (NULL)이 아닌 값이 생성됩니다.

이 상수는 NSLocale.h에 있습니다.