[英]How to swizzle []method of NSArray in iOS11?
我曾經破解過這樣的方法
Method originalMethod = class_getInstanceMethod([NSArray class], @selector(objectAtIndexedSubscript:));
Method swapMethod = class_getInstanceMethod([NSArray class], @selector(objectAtIndexedSubscriptNew:));
method_exchangeImplementations(originalMethod, swapMethod);
它在iOS10及之前可以正常工作,但在iOS11中不能工作,還有其他方法可以在iOS11中調配[]方法嗎?
從 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);
});
我將類從[NSArray class]
更改為NSClassFromString(@"__NSArrayI")
並且它現在工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.