クロージャーを使用すると、通常[weak self]
、キャプチャ リストに追加してから、自分自身に対して null チェックを行います。
func myInstanceMethod()
{
let myClosure =
{
[weak self] (result : Bool) in
if let this = self
{
this.anotherInstanceMethod()
}
}
functionExpectingClosure(myClosure)
}
クロージャーの代わりにネストされた関数を使用している場合にnull チェックを実行するにはどうself
すればよいですか (または、チェックが必要なのか... または、このようなネストされた関数を使用することをお勧めします) ie
func myInstanceMethod()
{
func nestedFunction(result : Bool)
{
anotherInstanceMethod()
}
functionExpectingClosure(nestedFunction)
}