久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

ARC 和橋接鑄件

ARC and bridged cast(ARC 和橋接鑄件)
本文介紹了ARC 和橋接鑄件的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

使用 ARC,我不能再將 CGColorRef 轉換為 id.我了解到我需要進行橋接演員表.根據 clang 文檔:

With ARC, I can no longer cast CGColorRef to id. I learned that I need to do a bridged cast. According clang docs:

橋接演員表是使用以下三個關鍵字之一注釋的 C 風格演員表:

A bridged cast is a C-style cast annotated with one of three keywords:

(__bridge T) op 將操作數轉換為目標類型 T.如果 T是一個可保留的對象指針類型,那么 op 必須有一個不可保留的指針類型.如果 T 是不可保留的指針類型,那么 op 必須有一個可保留的對象指針類型.否則演員表格式不正確.沒有所有權轉移,ARC插入沒有保留操作.

(__bridge T) op casts the operand to the destination type T. If T is a retainable object pointer type, then op must have a non-retainable pointer type. If T is a non-retainable pointer type, then op must have a retainable object pointer type. Otherwise the cast is ill-formed. There is no transfer of ownership, and ARC inserts no retain operations.

(__bridge_retained T) op 轉換操作數,它必須有可保留對象指針類型,指向目標類型,必須是不可保留的指針類型.ARC 保留價值,但須遵守通常對局部值進行優化,接收者負責用于平衡 +1.

(__bridge_retained T) op casts the operand, which must have retainable object pointer type, to the destination type, which must be a non-retainable pointer type. ARC retains the value, subject to the usual optimizations on local values, and the recipient is responsible for balancing that +1.

(__bridge_transfer T) op 轉換操作數,它必須有不可保留的指針類型,指向目標類型,它必須是可保留對象指針類型.ARC 會在最后釋放值封閉的完整表達式,服從通常的優化當地價值觀.

(__bridge_transfer T) op casts the operand, which must have non-retainable pointer type, to the destination type, which must be a retainable object pointer type. ARC will release the value at the end of the enclosing full-expression, subject to the usual optimizations on local values.

需要這些轉換才能將對象移入和移出電弧控制;參見關于轉換的部分的基本原理可保留的對象指針.

These casts are required in order to transfer objects in and out of ARC control; see the rationale in the section on conversion of retainable object pointers.

使用 __bridge_retained__bridge_transfer 轉換純粹是為了說服ARC分別發出不平衡的保留或釋放很差表格.

Using a __bridge_retained or __bridge_transfer cast purely to convince ARC to emit an unbalanced retain or release, respectively, is poor form.

我會在什么樣的情況下使用它們?

In what kind of situations would I use each?

例如,CAGradientLayer 有一個 colors 屬性,該屬性接受 CGColorRef 數組.我的猜測是我應該在這里使用 __brige,但我應該(或不應該)的確切原因尚不清楚.

For example, CAGradientLayer has a colors property which accepts an array of CGColorRefs. My guess is that I should use __brige here, but exactly why I should (or should not) is unclear.

推薦答案

我同意描述令人困惑.由于我剛剛掌握了它們,所以我將嘗試總結一下:

I agree that the description is confusing. Since I just grasped them, I'll try to summarize:

  • (__bridge_transfer <NSType>) opCFBridgingRelease(op) 用于消耗 CFTypeRef同時將其轉移到ARC.這也可以用 id someObj = (__bridge <NSType>) op; 來表示.CFRelease(op);

  • (__bridge_transfer <NSType>) op or alternatively CFBridgingRelease(op) is used to consume a retain-count of a CFTypeRef while transferring it over to ARC. This could also be represented by id someObj = (__bridge <NSType>) op; CFRelease(op);

(__bridge_retained <CFType>) op 或者 CFBridgingRetain(op) 用于將 NSObject 交給 CF-land 同時給它 +1 保留計數.您應該像處理 CFStringCreateCopy() 的結果一樣處理您創建的 CFTypeRef.這也可以用 CFRetain((__bridge CFType)op); 來表示.CFTypeRef someTypeRef = (__bridge CFType)op;

(__bridge_retained <CFType>) op or alternatively CFBridgingRetain(op) is used to hand an NSObject over to CF-land while giving it a +1 retain count. You should handle a CFTypeRef you create this way the same as you would handle a result of CFStringCreateCopy(). This could also be represented by CFRetain((__bridge CFType)op); CFTypeRef someTypeRef = (__bridge CFType)op;

__bridge 只是在指針域和 Objective-C 對象域之間進行轉換.如果您不想使用上述轉換,請使用此轉換.

__bridge just casts between pointer-land and Objective-C object-land. If you have no inclination to use the conversions above, use this one.

也許這會有所幫助.我自己,我更喜歡 CFBridging… 宏而不是普通的強制轉換.

Maybe this is helpful. Myself, I prefer the CFBridging… macros quite a bit over the plain casts.

這篇關于ARC 和橋接鑄件的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
UIScrollView scrolling only with one finger(UIScrollView 只能用一根手指滾動)
Using UITouch inside a UIScrollView(在 UIScrollView 中使用 UITouch)
UitextField resignFirstResponder does not work in scroll view(UitextField resignFirstResponder 在滾動視圖中不起作用)
How to Stop a UIScrollView from Swallowing Touches(如何阻止 UIScrollView 吞下觸摸)
Make background color change during scroll(在滾動期間更改背景顏色)
主站蜘蛛池模板: 97日日碰人人模人人澡分享吧 | 一区二区三区中文字幕 | 亚洲精品一区二区三区在线 | 91麻豆精品国产91久久久久久 | 欧美久 | 国产精品久久av | 热久久性 | 奇米四色在线观看 | 精品日韩一区二区三区 | 午夜激情在线视频 | 中文字幕成人av | 亚洲一二三区不卡 | 亚洲 欧美 日韩 在线 | 一区二区高清 | 日韩一二三 | h在线播放 | 日本久久黄色 | 青青操91| 欧美日韩亚洲视频 | 国产精品久久久久久久模特 | 日韩精品激情 | 日韩精品999 | 日本精品一区二区 | 九九亚洲 | 欧美日韩一区二区三区四区 | 五月天国产视频 | 最近免费日本视频在线 | 欧州一区 | 在线观看中文字幕视频 | 丁香六月伊人 | 夜夜操天天艹 | 欧美性久久 | 麻豆a级片 | 免费国产视频在线观看 | 国产精品日韩欧美一区二区三区 | 一区二区三区四区视频 | 天天久久| 99一级毛片 | 成人性生交大免费 | 欧美一区 | 欧美精品v|