3
從我目前的「按引用傳遞」的瞭解,推薦的方法(啓用ARC)是這樣的:IOS參照
-(void)somefunc:(someclass **)byref;
// and 'someclass **' should be inferred to 'someclass * __autoreleasing *'
// am i right?
//or we could just explicitly define it like
-(void)somefunc:(someclass * __autoreleasing *)byref;
然而,這個問題的答案線程,Handling Pointer-to-Pointer Ownership Issues in ARC。
似乎 - (void)somefunc:(someclass * __ strong *)byref也可以做到這一點(在上面的鏈接demo2中)。
1.-(void)somefunc:(someclass * __autoreleasing *)byref;
2.-(void)somefunc:(someclass *__strong *)byref
對於第一個,由蘋果公司爲證明應該由編譯器隱式地改寫這樣的:
NSError * __strong error;
NSError * __autoreleasing tmp = error;
BOOL OK = [myObject performOperationWithError:&tmp];
error = tmp;
看來,第二個有一個更好的表現?因爲它省略了「賦值返回」和「自動釋放」的過程。但我很少看到像這樣宣佈的函數。使用第二個函數來執行「通過參考」作業是否更好?
任何建議或解釋?提前致謝。
感謝您的回覆。但我不明白你的第二部分(想象...)。你能給我一個代碼示例/代碼段嗎? – 2013-03-28 02:01:08
沒有給定的原因,它被低估了兩次,所以沒有.... :) – 2013-03-28 11:01:05