Tag: 保留周期

对NSTimer目标的弱引用防止保留周期

我正在使用这样的NSTimer : timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:self selector:@selector(tick) userInfo:nil repeats:YES]; 当然, NSTimer保留了创build保留周期的目标。 此外, self不是一个UIViewController,所以我没有像viewDidUnload任何东西,我可以使计时器无效打破周期。 所以我想知道如果我可以使用一个弱引用: __weak id weakSelf = self; timer = [NSTimer scheduledTimerWithTimeInterval:30.0f target:weakSelf selector:@selector(tick) userInfo:nil repeats:YES]; 我听说计时器必须无效(我想从运行循环中释放它)。 但我们可以在我们的dealloc中这样做,对吧? – (void) dealloc { [timer invalidate]; } 这是一个可行的select? 我已经看到很多人处理这个问题的方法,但我没有看到这个。

如何正确处理有争议的快速障碍弱势群体

在我的TextViewTableViewCell ,我有一个variables来跟踪一个块和一个configuration方法,在这个块被传入和分配。 这是我的TextViewTableViewCell类: // // TextViewTableViewCell.swift // import UIKit class TextViewTableViewCell: UITableViewCell, UITextViewDelegate { @IBOutlet var textView : UITextView var onTextViewEditClosure : ((text : String) -> Void)? func configure(#text: String?, onTextEdit : ((text : String) -> Void)) { onTextViewEditClosure = onTextEdit textView.delegate = self textView.text = text } // #pragma mark – Text View Delegate […]