문제

I have a property on my class that is of type NSNumber.

 @property (nonatomic, strong) NSNumber *createdDate;

I want it to stay NSNumber for the life of the class. However, I want to make a date out of it when another class requests it.

For that I made a method called getCreatedDate

Here is the method that I created

 - (NSDate *)getCreatedDate
 {
   NSNumber *copyCreatedDate = [[NSNumber alloc] initWithDouble:[self.createdDate doubleValue]];
   NSDate *dateFromNumber = [NSDate dateWithTimeIntervalSince1970:[copyCreatedDate doubleValue]];
   return dateFromNumber;
 }

The problem is after that method is run, I check to see what type the property self.createdDate is and it tells me its of type NSDate.

Does anyone know if what I want to do it possible?

도움이 되었습니까?

해결책

The problem is in your method name. getCreatedDate will represent the getter method of the createdDate object. So after implementing this method, u returned NSDate datatype. Thats why the type changes to NSDate . So you have to change the name to another

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top