2011-09-25 11 views
9

In un ambiente ARC, ho il seguente codice:Tipo conversione del & sé provoca errore del compilatore

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]; 

Impostare l'argomento di indice 2 (&self) causa il seguente errore del compilatore:

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

Non ho idea di come risolvere questo problema mantenendo il codice valido. Al momento sto semplicemente inserendo NULL e avvolgendo l'istruzione invoke in un blocco try/catch, ma questa è una soluzione tutt'altro che ideale.


Un problema simile, se qualcuno sarebbe così gentile da affrontare pure:

Con questa riga di codice (dalla libreria MPOAuth)

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

ottengo il seguente errore

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

+1

C'è qualche motivo particolare per cui si desidera utilizzare NSInvocation anziché un blocco qui? – NSResponder

+0

Non sono sicuro, fa parte dell'SDK Dropbox. Sto solo verificando che sia compatibile con ARC, cercando di non rovinare troppo il codice. – FeifanZ

risposta

0

Piuttosto che cambiare l'SDK (Dropbox ha detto che presto pubblicheranno una versione compatibile con ARC), ho scoperto che posso usare ARC in modo selettivo per un file. Così l'ho fatto.

E quindi ho eseguito l'aggiornamento a 1.0b2, che è impacchettato come libreria e quindi il problema è risolto.

13

Dovresti riuscire a eseguire il cast per ottenere un tipo di puntatore appropriato:

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

questa linea:

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

possono essere risolti come segue:

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

Quindi, in sostanza basta dare il tipo di riferimento che si aspetta come il parametro fuori. E quando il parametro out è compilato, trasferisci la proprietà al tuo tipo di cacao.

Problemi correlati