日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Resolving Strong Reference Cycles for Closures

發布時間:2023/12/20 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Resolving Strong Reference Cycles for Closures 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

You resolve a strong reference cycle between a closure and a class instance by defining a?capture list?as part of the closure’s definition. A capture list defines the rules to use when capturing one or more reference types within the closure’s body. As with strong reference cycles between two class instances, you declare each captured reference to be a weak or unowned reference rather than a strong reference. The appropriate choice of weak or unowned depends on the relationships between the different parts of your code.

NOTE

Swift requires you to write?self.someProperty?or?self.someMethod()?(rather than just?someProperty?or?someMethod()) whenever you refer to a member of?self?within a closure. This helps you remember that it’s possible to capture?self?by accident.

Defining a Capture List

Each item in a capture list is a pairing of the?weak?or?unowned?keyword with a reference to a class instance (such as?self) or a variable initialized with some value (such as?delegate = self.delegate!). These pairings are written within a pair of square braces, separated by commas.

Place the capture list before a closure’s parameter list and return type if they are provided:

  • lazy var someClosure: (Int, String) -> String = {
  • [unowned self, weak delegate = self.delegate!] (index: Int, stringToProcess: String) -> String in
  • // closure body goes here
  • }
  • If a closure does not specify a parameter list or return type because they can be inferred from context, place the capture list at the very start of the closure, followed by the?in?keyword:

  • lazy var someClosure: () -> String = {
  • [unowned self, weak delegate = self.delegate!] in
  • // closure body goes here
  • }
  • Weak and Unowned References

    Define a capture in a closure as an unowned reference when the closure and the instance it captures will always refer to each other, and will always be deallocated at the same time.

    Conversely, define a capture as a weak reference when the captured reference may become?nil?at some point in the future. Weak references are always of an optional type, and automatically become?nil?when the instance they reference is deallocated. This enables you to check for their existence within the closure’s body.

    NOTE

    If the captured reference will never become?nil, it should always be captured as an unowned reference, rather than a weak reference.

    ?

    總結

    以上是生活随笔為你收集整理的Resolving Strong Reference Cycles for Closures的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 久久久久久久久亚洲 | 日本欧美国产在线 | 亚洲狠狠干| 精品国产免费无码久久久 | 国产成人精品国内自产拍免费看 | 亚洲国产成人91精品 | 亚洲精品久久久蜜桃 | 在线视频福利 | 超碰在线公开免费 | 免费草逼网站 | 美国做爰xxxⅹ性视频 | 国产精品外围 | 男生操女生逼逼 | 中文字幕亚洲区 | 婷婷丁香社区 | 亚洲美女操 | 亚洲热在线 | 爱上av| 91黄色小网站 | 五月天激情啪啪 | 日韩av成人| 久久99网站 | 国产精品一二三区 | 大奶子在线观看 | 久久高清内射无套 | 日本国产精品 | 国产精品三区在线观看 | 中文在线字幕av | 欧美啪啪网站 | 色版视频| 日本丰满熟妇bbxbbxhd | 亚洲一区二区三区四区不卡 | 黄色毛毛片 | 国产日韩欧美在线观看视频 | 亚洲一区不卡 | 杨幂毛片 | 亚洲黄色三级 | 男女做那个的全过程 | 亚洲午夜精品久久久久久人妖 | 99热在线观看 | 韩国主播青草200vip视频 | 欧美黄色一级视频 | 国产午夜一级一片免费播放 | 美女干b视频| 天天做夜夜爽 | www黄色网址| 久久成人久久 | 99久久精品国产成人一区二区 | 亚洲专区欧美专区 | 波多野一区二区 | 91在线播 | 国产欧美日韩高清 | 无遮挡无掩盖网站 | 91av俱乐部 | av黄在线| 久久国产精品亚洲 | 自拍偷拍国内 | 亚洲人成在线免费观看 | 亚洲精品久久久中文字幕痴女 | v888av| 清纯粉嫩极品夜夜嗨av | 91在线高清| 国产亚洲天堂 | 91夜色视频 | 日韩少妇一区二区三区 | 99精品在线观看视频 | 女同性恋毛片 | 在线观看av资源 | 老女人毛片 | 国产黄色片免费看 | 农村妇女毛片精品久久久 | www.国产一区| 亚洲免费色视频 | 成 人 黄 色 片 在线播放 | 91丨porny丨在线中文 | 国语av | 人妻少妇精品视频一区二区三区 | 免费的一级片 | av午夜在线 | 成人免费视频国产免费麻豆 | 一级视频片 | av中文资源网 | 内射国产内射夫妻免费频道 | 欧美亚洲久久 | 韩国三级与黑人 | 日日拍夜夜拍 | 日本免费黄色大片 | 青春草在线视频免费观看 | 亚洲13p| 91自啪| 先锋影音av资源在线观看 | 成人av网址大全 | 僵尸叔叔在线观看国语高清免费观看 | 性中文字幕| 精品一区二区久久久 | 在线观看中文字幕av | 亚洲精品伊人 | 在线观看免费观看 | 亚欧精品在线观看 |