Search code examples
iosobjective-cswiftclosuresweak

What is the Objective-C equivalent of 'weak self' in a Swift closure?


Could you tell me the equivalent of:

var didTapURL: ((_ url: URL) -> Void)?

..........

myObject.didTapURL = { [weak self] (url) in
     self?.manageUrl(url)
}

in Objectice-C?


Solution

  • It is __weak, see below

    __weak __typeof(self) weakSelf = self;
    
    // ...
    
        dispatch_async(dispatch_get_main_queue(), ^{
          [weakSelf call_some_selector];
        });