0
obj-c 프로젝트를 신속하게 변환하는 상황이 있습니다. 다음과 같습니다.객관적인 -c 동적 바인딩을 신속하게 변환 2
// 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.
걱정되는 점은 무엇입니까?
아, 우리는 스위프트에서이 작업을 수행 할 수없는 감사의 신 여기에 간단한 대안이 확실히 가능하지만, 매우 유연 하나 개의 솔루션입니다. – Sulthan