我知道有關塊的最佳做法就是這樣塊很強的參考
__weak SomeObjectClass *weakSelf = self;
SomeBlockType someBlock = ^{
SomeObjectClass *strongSelf = weakSelf;
if (strongSelf == nil) {
// The original self doesn't exist anymore.
// Ignore, notify or otherwise handle this case.
}
[self someMethod];
};
我瞭解使用weakSelf是用來防止在weakSelf的情況下保留週期和使用strongSelf可能爲零。 但我只是想知道使用strongSelf可以導致保留週期再次因爲塊捕獲並保留強自己和強自己也是自己的指針。 有人可以給我一個解釋,謝謝。
注:'__weak'指針_can_被用於避免保留週期。但是,即使您在代碼塊中意外使用了_self_,您的代碼也沒有保留週期 - 而不是使用_strongSelf_。 – CouchDeveloper