iOS 5 Twitter Framework & completionHandler block - “Capturing 'self' strongly in this block is likely to lead to a retain cycle”

前端 未结 4 1112
失恋的感觉
失恋的感觉 2021-02-14 13:51

I am very new to programming and Objective-C and I am trying to work out what is wrong with my code. I have read a bit about blocks but I don\'t know how any of what I have read

4条回答
  •  失恋的感觉
    2021-02-14 14:19

    According to stuff I've seen elsewhere, “weak” won't work for ARC-compliant code, and that you must use “_unsafe_unretained” instead. This is what I did to fix the “Capturing 'self' strongly in this block is likely to lead to a retain cycle” warning in the Apple sample app "AVPlayerDemo":

    __unsafe_unretained id unself = self;
    mTimeObserver = [mPlayer addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(interval, NSEC_PER_SEC) 
                                queue:NULL /* If you pass NULL, the main queue is used. */
                                usingBlock:^(CMTime time) 
                                            {
                                                /* 'unself' replaced 'self' here: */
                                                [unself syncScrubber];
                                            }];
    

提交回复
热议问题