objective c - Convert Obj C code to Swift weak self -
i using code here i'm having difficulty convert the
__weak __typeof(self) weakself = self; to swift. there way me convert following code swift? i'm stucked convert swift after reading material said [unowned self] or [weak self].
__weak __typeof(self) weakself = self; uiviewcontroller *controller = [self.gamingpageviewcontroller viewcontrolleratindex:index]; [self.gamingpageviewcontroller setviewcontrollers:@[controller] direction:(self.gamingpageindex<index)?uipageviewcontrollernavigationdirectionforward:uipageviewcontrollernavigationdirectionreverse animated:no completion:^(bool finished) { // method not mess view order in pageview uipageviewcontroller* pvcs = weakself.gamingpageviewcontroller; if (!pvcs) return; dispatch_async(dispatch_get_main_queue(), ^{ [pvcs setviewcontrollers:@[controller] direction:uipageviewcontrollernavigationdirectionforward animated:no completion:nil]; }); }];
in swift don't need declare weakself variable outside closure.
just define completion block follows:
{ [weak self] (finished) -> () in ... } and use self? inside block, in case may nil.
if self cannot nil, may need use [unowned self] instead of [weak self].
Comments
Post a Comment