iOS bridge vs bridge_transfer

后端 未结 4 1536
旧巷少年郎
旧巷少年郎 2021-01-31 03:27

I\'m confused with bridge and bridge_transfer, is this correct?

-(void)getData{
    ABAddressBookRef addressBook = ABAddressBookCreate(         


        
4条回答
  •  悲哀的现实
    2021-01-31 03:54

    If you have automatic-reference-counting (ARC) turned on, the code is correct.

    There are two __bridge_transfer in your statements. As a result, the ownership of created CFObjects will be transferred to NSObjects. If you have ARC turned on, they will be freed up automatically. If you used __bridge instead for these 2 statements, you will need to explicitly call CFRelease to release CFObjects created by the *Copy API.

    The __bridge statement is also correct. Because you are referencing an NSObject in CF API. You are not transferring ownership, so that ARC will free it up.

提交回复
热议问题