【发布时间】:2016-07-09 15:35:32
【问题描述】:
我有一种情况,我正在将 obj-c 项目转换为 swift。如下
// few lazy property initializers as,
@property (nonatomic, strong) MyObject *property1;
@property (nonatomic, strong) MyObject *property2;
@property (nonatomic, strong) MyObject *property3;
...
// I keep an index value to map these into a dictionary for reference
- (NSDictionary *)indexMap
{
if (!_indexMap)
{
_indexMap = @{
@(index1) : [NSValue valueWithPointer:@selector(property1)],
@(index2) : [NSValue valueWithPointer:@selector(property2)],
...
};
}
return _indexMap;
}
// other dictionary for index to class map
- (NSDictionary *)classMap
{
return @{
NSStringFromClass(@"MyClassA") : @(index1),
NSStringFromClass(@"MyClassB") : @(index1),
NSStringFromClass(@"MyClassC") : @(index1),
NSStringFromClass(@"MyClassD") : @(index2),
NSStringFromClass(@"MyClassE") : @(index2),
NSStringFromClass(@"MyClassF") : @(index3),
...
};
}
// finally i have method to pass in the class name & it will first find corresponding index, then use the index to return the property selector.
我担心的是这样做的快速方式是什么?
【问题讨论】:
-
哦,感谢上帝,我们不能在 Swift 中做到这一点。
标签: ios swift dynamic-binding dynamic-dispatch