質問

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