假设我们有一个带有NSTimeInterval属性的类:
@interface MyClass : NSObject {
NSTimeInterval timeSpent;
}
@property (assign) NSTimeInterval timeSpent;
然后我就可以得到属性的类型:
const char * type = property_getAttributes(class_getProperty([MyClass class], "timeSpent"));
...其中type
类似于:Td, VtimeSpan
,其中“d”表示它是双精度(这是正常的,因为文档说typedef double NSTimeInterval
)
为了找出timeSpent属性最初被声明为NSTimeInterval,我能做些什么吗?
谢谢!
答案 0 :(得分:1)
你做不到。 NSTimeInterval
是typedef
的{{1}},这意味着它与新名称完全相同。这对于编写自我记录代码很方便,但它不会改变关于类型的任何内容。 (它还允许在保持源兼容的同时更改基础类型;它们可以将double
更改为NSTimeInterval
或float
的别名或完全不同的其他内容,并且您的代码不会'需要关心。)
你有理由关心吗?您是否尝试编写一些通用代码,以不同于常规数字的方式处理时间间隔?你有什么最终目标?