2017-10-09 2 views
-1

が、私はそれはiOS10中と前正常に動作しますが、それはiOS11で働くことができないiOS11でNSArrayの[]メソッドをスウィズルする方法はありますか?

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

のような方法をハックするために使用、私たちはiOS11で[]メソッドをスウィズルことができる任意の他の方法は何ですか?

+0

iOS 11でうまく動作します。テストしました。これが一度だけ呼び出されることを確認する必要があります。 – Brandon

答えて

-1

クラスを[NSArray class]からNSClassFromString(@"__NSArrayI")に変更しました。現在は正常に動作しています。

0

iOS 11では、私がまだ研究している何らかの理由で、スウィズルメソッドは一度呼び出す必要があります。

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); 
}); 
関連する問題