-
Notifications
You must be signed in to change notification settings - Fork 266
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
开启后,WeakProxy NSTimer定时针失效 #97
Comments
因为你用了 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
直接使用YYTextWeakProxy 定时器还是失效
self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:[YYTextWeakProxy proxyWithTarget:self] selector:@selector(timerEvent1:) userInfo:nil repeats:YES];
// self.timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(timerEvent1:) userInfo:nil repeats:YES];
[[NSRunLoop currentRunLoop] addTimer:self.timer forMode:NSRunLoopCommonModes];
#import <Foundation/Foundation.h>
NS_ASSUME_NONNULL_BEGIN
/**
A proxy used to hold a weak object.
It can be used to avoid retain cycles, such as the target in NSTimer or CADisplayLink.
sample code:
@implementation MyView {
NSTimer *_timer;
}
(void)initTimer {
YYTextWeakProxy *proxy = [YYTextWeakProxy proxyWithTarget:self];
_timer = [NSTimer timerWithTimeInterval:0.1 target:proxy selector:@selector(tick:) userInfo:nil repeats:YES];
}
(void)tick:(NSTimer *)timer {...}
@EnD
*/
@interface YYTextWeakProxy : NSProxy
/**
The proxy target.
*/
@Property (nullable, nonatomic, weak, readonly) id target;
/**
Creates a new weak proxy for target.
@param target Target object.
@return A new proxy object.
*/
(instancetype)initWithTarget:(id)target;
/**
Creates a new weak proxy for target.
@param target Target object.
@return A new proxy object.
*/
(instancetype)proxyWithTarget:(id)target;
@EnD
#import "YYTextWeakProxy.h"
@implementation YYTextWeakProxy
(instancetype)initWithTarget:(id)target {
_target = target;
return self;
}
(instancetype)proxyWithTarget:(id)target {
return [[YYTextWeakProxy alloc] initWithTarget:target];
}
(id)forwardingTargetForSelector:(SEL)selector {
return _target;
}
(void)forwardInvocation:(NSInvocation *)invocation {
void *null = NULL;
[invocation setReturnValue:&null];
}
(NSMethodSignature *)methodSignatureForSelector:(SEL)selector {
return [NSObject instanceMethodSignatureForSelector:@selector(init)];
}
(BOOL)respondsToSelector:(SEL)aSelector {
return [_target respondsToSelector:aSelector];
}
(BOOL)isEqual:(id)object {
return [_target isEqual:object];
}
(NSUInteger)hash {
return [_target hash];
}
(Class)superclass {
return [_target superclass];
}
(Class)class {
return [_target class];
}
(BOOL)isKindOfClass:(Class)aClass {
return [_target isKindOfClass:aClass];
}
(BOOL)isMemberOfClass:(Class)aClass {
return [_target isMemberOfClass:aClass];
}
(BOOL)conformsToProtocol:(Protocol *)aProtocol {
return [_target conformsToProtocol:aProtocol];
}
(BOOL)isProxy {
return YES;
}
(NSString *)description {
return [_target description];
}
(NSString *)debugDescription {
return [_target debugDescription];
}
@EnD
The text was updated successfully, but these errors were encountered: