我正在使用ARC专门为iOS 5开发.应该IBOutlets UIView(和子类)是strong或weak?
下列:
@property (nonatomic, weak) IBOutlet UIButton *button;
Run Code Online (Sandbox Code Playgroud)
将摆脱所有这一切:
- (void)viewDidUnload
{
// ...
self.button = nil;
// ...
}
Run Code Online (Sandbox Code Playgroud)
这样做有什么问题吗?模板正在使用strong,当从"Interface Builder"编辑器直接连接到标题时创建的自动生成属性,但为什么?在UIViewController已经有一个strong到其基准view保留其子视图.
cocoa-touch objective-c interface-builder ios automatic-ref-counting
I have created a class called VerifyObject, that contains a function with a signature like that
typealias handlerCodeID = (String) ->Void
class func checkPause(withID:String?,
runOnPause: handlerCodeID?)
Run Code Online (Sandbox Code Playgroud)
When I run that, I need to pass a weak self reference to inside the closure, using
VerifyObject.checkPause(withID: "abcde",
runOnPause: {[weak self] (objectID) in
self.doSomething()
})
Run Code Online (Sandbox Code Playgroud)
Xcode complains that the self in doSomething must be unwrapped to
self!.doSomething()
Run Code Online (Sandbox Code Playgroud)
why? Does not make sense.