2017-10-09 1 views
-1

내가iOS11에서 NSArray의 [] 메소드를 사용하는 방법은 무엇입니까?

Method originalMethod = class_getInstanceMethod([NSArray class], @selector(objectAtIndexedSubscript:)); 
Method swapMethod = class_getInstanceMethod([NSArray class], @selector(objectAtIndexedSubscriptNew:)); 
method_exchangeImplementations(originalMethod, swapMethod); 

그것은 iOS10와 전에 잘 작동과 같은 방법을 해킹하는 데 사용하지만,이 iOS11에서 작동하지 않을 수 있습니다 우리가 iOS11에서 [] 방법을 스위 즐링 (swizzle) 할 수있는 다른 방법은?

+0

iOS 11에서 잘 작동합니다. 방금 테스트했습니다. 이 작업은 한 번만 호출해야합니다. – Brandon

답변

-1

클래스를 [NSArray class]에서 NSClassFromString(@"__NSArrayI")으로 변경하고 현재 정상적으로 작동합니다.

0

iOS 11부터, 아직 연구 중이라는 이유로 swizzle 메서드를 한 번만 호출해야합니다.

static dispatch_once_t once; 
dispatch_once(&once, ^{  
    Method originalMethod = class_getInstanceMethod([NSArray class], @selector(objectAtIndexedSubscript:)); 
    Method swapMethod = class_getInstanceMethod([NSArray class], @selector(objectAtIndexedSubscriptNew:)); 
    method_exchangeImplementations(originalMethod, swapMethod); 
}); 
관련 문제