鉴于以下内容:
- (void) someMethod
{
dispatch_async(dispatch_get_main_queue(), ^{
myTimer = [NSTimer scheduledTimerWithTimeInterval: 60
target: self
selector: @selector(doSomething)
userInfo: nil
repeats: NO];
});
}
Run Code Online (Sandbox Code Playgroud)
在私有接口中声明myTimer的位置:
@interface MyClass()
{
NSTimer * myTimer;
}
@end
Run Code Online (Sandbox Code Playgroud)
如何修复以下警告:
Block implicitly retains 'self'; explicitly mention 'self' to indicate this is intended behavior
从我迄今发现的内容来看,大多数建议涉及到如下内容:
- (void) someMethod
{
__typeof__(self) __weak wself = self;
dispatch_async(dispatch_get_main_queue(), ^{
wself.myTimer = [NSTimer scheduledTimerWithTimeInterval: 60
target: self
selector: @selector(doSomething)
userInfo: nil
repeats: NO];
});
}
Run Code Online (Sandbox Code Playgroud)
除此之外,myTimer是一个ivar,意思wself是无法访问任何属性.
我想我的问题是:
我在代码中使用了很多ivars.我刚刚将-Weverything …