我得到这两个错误: - 不能使用对象作为方法的参数 - 作为回报的类型不兼容
那是我的代码:
- (NSString) dateStringFromUnixTimeStamp:(NSInteger)timeStamp {
//Create Date-String from UNIX-Time-Stamp:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];
NSDateComponents *monthComponents = [[NSCalendar currentCalendar] components:NSMonthCalendarUnit fromDate:date];
int month = [monthComponents month];
NSDateComponents *dayComponents = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:date];
int day = [dayComponents day] - 1;
NSDateComponents *yearComponents = [[NSCalendar currentCalendar] components:NSYearCalendarUnit fromDate:date];
int year = [yearComponents year];
NSString *monthString;
switch (month) {
case 1:
monthString = @"Januar";
break;
case 2:
monthString = @"Februar";
break;
case 3:
monthString = @"März";
break;
case 4:
monthString = @"April";
break;
case 5:
monthString = @"Mai";
break;
case 6:
monthString = @"Juni";
break;
case 7:
monthString = @"Juli";
break;
case 8:
monthString = @"August";
break;
case 9:
monthString = @"September";
break;
case 10:
monthString = @"Oktober";
break;
case 11:
monthString = @"November";
break;
case 12:
monthString = @"Dezember";
break;
default:
break;
}
NSString *dateString = [[NSString stringWithFormat:@"%d", day] stringByAppendingString:@". "];
dateString = [dateString stringByAppendingString:monthString];
dateString = [dateString stringByAppendingString:@" "];
dateString = [dateString stringByAppendingString:[NSString stringWithFormat:@"%d", year]];
return dateString;
}
感谢帮助!