xcode - "NSDate not an Objective-C object" error shows when run the application in IOS 7 in real device -
nsdate object working iphone, ipad when ran application in real devices. when run application in ipad real device gives <not objective-c object>
error. tried sort out it. couldn't.
- (nsstring*)getdatefromjsontostringsaveformat:(nsstring *)datestring { nsdate *_date = [nsdate alloc] init]; nsdate *_date = [self getdatefromjson:datestring]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"yyyy-mm-dd"]; return [dateformatter stringfromdate:_date]; } - (nsdate*) getdatefromjson:(nsstring *)datestring { // expect date in format "/date(1268123281843)/" int startpos = [datestring rangeofstring:@"("].location+1; int endpos = [datestring rangeofstring:@")"].location; nsrange range = nsmakerange(startpos,endpos-startpos); unsigned long long milliseconds = [[datestring substringwithrange:range] longlongvalue]; nstimeinterval interval = milliseconds/1000; return [nsdate datewithtimeintervalsince1970:interval]; }
because of issue initialize nsdate object , saw date value. (nsdate *_date = [nsdate alloc] init];
) in here gives same error? why that? faced error ??
first off can remove line:
nsdate *_date = [nsdate alloc] init];
since next line redeclares it, in line should remove missing [
.
- (nsstring*)getdatefromjsontostringsaveformat:(nsstring *)datestring { // not needed since line after declares variable. //nsdate *_date = [nsdate alloc] init]; nsdate *_date = [self getdatefromjson:datestring]; nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"yyyy-mm-dd"]; return [dateformatter stringfromdate:_date]; }
Comments
Post a Comment