views:

102

answers:

1

I get those two errors: - Can not use an object as parameter to a method - Incompatible types in return

That's my code:

 - (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;
}

Thanks for help!

+2  A: 

The return type of your method must be NSString * instead of NSString.

That said, your method is much more complex than it has to be. You should use an NSDateFormatter to format a date. Turns this method into a handful of lines.

Also, if you report error messages, you should always tell us on what line the error occurs.

Ole Begemann
Thanks helped a lot! I'll try it with NSDateFormatter.
pbcoder
If this answers your question, you should mark the answer as accepted.
Ole Begemann