亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

objective-c - iOS中[unowned self]的問題
天蓬老師
天蓬老師 2017-04-17 17:43:18
0
3
354
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let person = people[indexPath.item]

    let ac = UIAlertController(title: "Rename person", message: nil, preferredStyle: .Alert)
    ac.addTextFieldWithConfigurationHandler(nil)

    ac.addAction(UIAlertAction(title: "Cancel", style: .Cancel, handler: nil))

    ac.addAction(UIAlertAction(title: "OK", style: .Default) { [unowned self, ac] _ in
        let newName = ac.textFields![0]
        person.name = newName.text!

        self.collectionView.reloadData()
    })

    presentViewController(ac, animated: true, completion: nil)
}

在上面這段代碼中為什么需要[unowned self]

天蓬老師
天蓬老師

歡迎選擇我的課程,讓我們一起見證您的進(jìn)步~~

reply all(3)
迷茫

Prevent 當(dāng)前VC(self) -> UIAlertController -> 閉包 -> 當(dāng)前VC circular references

In addition, the ac parameter within the closure should also be weak or unowned

劉奇

You can check out Apple’s official documentation

developer.apple.com/library
https://developer.apple.com/library/ios/documentation/Swift/Conceptual/Swift_Programming_Language/AutomaticReferenceCounting.html#//apple_ref/doc/uid/TP40014097-CH20-ID48

洪濤

For this code, there is no need. unowned,雖然閉包持有self的引用,但是self does not hold a reference to the closure, so it does not constitute a circular reference.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template