Hi,
When I run my Demo on my iPhone or simulator with system iOS11.2 , textField never perform dealloc. For a long time, I cann't find any sulution for this problem.
So I find help here for some progress, Thanks!
Hi,
When I run my Demo on my iPhone or simulator with system iOS11.2 , textField never perform dealloc. For a long time, I cann't find any sulution for this problem.
So I find help here for some progress, Thanks!
This appears to be fixed in Xcode 9.3 beta
I have a different fix for that, a little bit safer I think 🙂. Following code uses Aspects and TPDWeakProxy:
@implementation UITextField (iOS_11_2_Fix)
+ (void)agc_fixMe {
NSError *error = nil;
Class contentViewClass = NSClassFromString(@"_UITextFieldContentView");
SEL initializerSelector = NSSelectorFromString(@"initWithContentContextProvider:");
if (![contentViewClass respondsToSelector:initializerSelector]) {
return;
}
id<AspectToken> token =
[contentViewClass aspect_hookSelector:initializerSelector
withOptions:AspectPositionInstead
usingBlock:^(id<AspectInfo> aspectInfo, id provider) {
NSInvocation *invocation = aspectInfo.originalInvocation;
id originalProvider = aspectInfo.arguments.lastObject;
TPDWeakProxy *proxyProvider = [[TPDWeakProxy alloc] initWithObject:originalProvider];
[invocation setArgument:&proxyProvider atIndex:2];
[invocation invoke];
// Eagerly load _fieldEditor to prevent crash at dealloc
// (looks like another iOS bug which is not visible because of the retain cycle).
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
[originalProvider performSelector:NSSelectorFromString(@"_fieldEditor")];
#pragma clang diagnostic pop
}
error:&error];
NSAssert(token != nil, @"Token should not be nil");
NSAssert(error == nil, @"Error should be nil, was %@", error);
}
@end