ios - Do I need to check for nil on my strongSelf = weakSelf assignment inside a block? -
for example, i'm using svinfinitescrolling (https://github.com/alexanderedge/svinfinitescrolling).
i have code looks this...
- (void)initializeinfinitescrollingfortableview { __weak myviewcontroller *weakself = self; [self.tableview addinfinitescrollingwithactionhandler:^{ myviewcontroller *strongself = weakself; if (!strongself.endreached) { [strongself fetchdata]; } else { [strongself.tableview.infinitescrollingview stopanimating]; } }]; }
what i'm wondering is... need check strongself nil before using this...
... [self.tableview addinfinitescrollingwithactionhandler:^{ myviewcontroller *strongself = weakself; if (strongself) { // <== ** needed? ** if (!strongself.endreached) {
here why ask. point #3 on link (http://www.apeth.com/iosbook/ch12.html#exstrongweakdance) says "the nil test because, in multithreaded situation, our weak reference self may have vanished out under before previous step; nil, because it’s arc weak reference, , in case there no point continuing."
is check needed? thought first time used reference weakself within block, retained duration of expression?
i think in line:
if (!strongself.endreached) {
this evaluate yes if self nil, not not intend.
it happens code correct thing (do nothing) because both clauses use self call methods , nothing happen. end result same if had nil-check execution path wrong. might have consequences in future if adds code doesn't use self.
Comments
Post a Comment