Reputation: 9722
I have this in my interface:
@property (nonatomic, weak) NSTimeInterval *timeStamp;
Which my logic told me, I need a time stamp object, that only is going to be used by this class within the context of its instantiation, so "weak" seemed to be logical to me-- but XCode tells me "property with 'weak' attribute must be of object type"... If I just do:
@property (nonatomic) NSTimeInterval *timeStamp;
Then the error goes away, but I am not sure I understand why...
Upvotes: 8
Views: 10286
Reputation:
The problem is that NSTimeInterval
is a value type -- it's an alias for double
, essentially (check NSDate.h for the typedef). The weak
attribute only applies to objects that have a retain count (that is, anything that descends from NSObject
or NSProxy
).
As such, storing a pointer to NSTimeInterval
is probably a mistake on your part. You will most likely never receive a pointer to an NSTimeInterval
unless you're expected to write to a given address as an output to a function (probably a callback in such a case). That said, I'm not aware of any functions with NSTimeInterval *
as a return type nor any that pass the same to a callback.
Upvotes: 14