2011-09-25 6 views
9

का कारण बनता है एक एआरसी वातावरण में, मैं निम्नलिखित कोड है:प्रकार रूपांतरण संकलक त्रुटि

NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature]; 
[invocation setTarget:delegate]; 
[invocation setSelector:@selector(restClient:loadedFile:contentType:eTag:)]; 
// Error Here! 
[invocation setArgument:&self atIndex:2]; 
[invocation setArgument:&filename atIndex:3]; 
[invocation setArgument:&contentType atIndex:4]; 
[invocation setArgument:&eTag atIndex:5]; 

सूचकांक 2 (&self) करने के लिए तर्क की स्थापना निम्नलिखित संकलक त्रुटि होती है:

Sending *const __strong * to parameter of type void * changes retain/release properties

मुझे नहीं पता कि वैध कोड रखने के दौरान इसे कैसे ठीक किया जाए। फिलहाल मैं NULL में चिपक रहा हूं और आवेदक कथन को एक कोशिश/पकड़ ब्लॉक में लपेट रहा हूं, लेकिन यह एक आदर्श से कम समाधान है।


ऐसा ही एक मुद्दा है, किसी को भी तरह पर्याप्त होगा अगर यह रूप में अच्छी तरह पता करने के लिए:

कोड की इस पंक्ति (MPOAuth पुस्तकालय से)

status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary); 

मैं निम्नलिखित त्रुटि मिलती है साथ

Cast of an indirect pointer to an Objective-C pointer to 'CFTypeRef ' (aka 'const void *') is disallowed with ARC

+1

क्या कोई विशेष कारण है कि आप यहां एक ब्लॉक के बजाय एनएसआईएनवोकेशन का उपयोग क्यों करना चाहते हैं? – NSResponder

+0

मुझे यकीन नहीं है, यह ड्रॉपबॉक्स एसडीके का हिस्सा है। मैं इसे एआरसी-अनुपालन बनाने के माध्यम से जा रहा हूं, कोड को गड़बड़ न करने की कोशिश कर रहा हूं। – FeifanZ

उत्तर

0

एसडीके को बदलने की बजाय (ड्रॉपबॉक्स ने कहा है कि वे जल्द ही एआरसी-संगत संस्करण पोस्ट करेंगे), मुझे पता चला कि मैं एक फ़ाइल के लिए चुनिंदा एआरसी का उपयोग कर सकता हूं। तो मैंने ऐसा किया।

और फिर मैंने 1.0b2 में अपग्रेड किया, जिसे लाइब्रेरी के रूप में पैक किया गया है और इसलिए समस्या हल हो गई है।

13

आप इसे कास्ट करने के लिए एक उचित सूचक प्रकार प्राप्त करने के लिए सक्षम होना चाहिए:

NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature]; 
[invocation setTarget:delegate]; 
[invocation setSelector:@selector(restClient:loadedFile:contentType:eTag:)]; 
Foo *foo = self; 
[invocation setArgument:&foo atIndex:2]; 
[invocation setArgument:&filename atIndex:3]; 
[invocation setArgument:&contentType atIndex:4]; 
[invocation setArgument:&eTag atIndex:5]; 
2

इस लाइन:

status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, (CFTypeRef *)&attributesDictionary); 

निम्नलिखित के रूप में हल किया जा सकता:

CFTypeRef outDictionaryRef; 
status = SecItemCopyMatching((__bridge CFDictionaryRef)searchDictionary, &outDictionaryRef; 
attributesDictionary = (__bridge_transfer NSDictionary *) outDictionaryRef; 

तो सार में सिर्फ संदर्भ प्रकार इसे बाहर परम के रूप में की उम्मीद दे। और जब बाहर परम भर जाता है, स्वामित्व को अपने कोको प्रकार में स्थानांतरित करें।

 संबंधित मुद्दे

  • कोई संबंधित समस्या नहीं^_^