0

次のエラーが表示されます

Sending "NSString *_strong*to parameter of type _unsafe_unretained id* "changes retain/release properties of pointer...

次の行に: [theDict getObjects:values andKeys:keys]; 連絡先からアプリにアドレスを追加しようとしています。誰かが私に何について不平を言っているのか説明してもらえますか? おそらく手動のメモリ管理に関係するARCの問題だと思いますか?しかし、それを修正する方法がわかりません。

   - (BOOL)peoplePickerNavigationController:
(ABPeoplePickerNavigationController *)peoplePicker
  shouldContinueAfterSelectingPerson:(ABRecordRef)person
                            property:(ABPropertyID)property
                          identifier:(ABMultiValueIdentifier)identifier


 {
    if (property == kABPersonAddressProperty) {
    ABMultiValueRef multi = ABRecordCopyValue(person, property);

    NSArray *theArray = (__bridge id)ABMultiValueCopyArrayOfAllValues(multi);

    const NSUInteger theIndex = ABMultiValueGetIndexForIdentifier(multi, identifier);

    NSDictionary *theDict = [theArray objectAtIndex:theIndex];

    const NSUInteger theCount = [theDict count];

    NSString *keys[theCount];

    NSString *values[theCount];

    [theDict getObjects:values andKeys:keys]; <<<<<<<<< error here

    NSString *address;
    address = [NSString stringWithFormat:@"%@, %@, %@",
               [theDict objectForKey: (NSString *)kABPersonAddressStreetKey],
               [theDict objectForKey: (NSString *)kABPersonAddressZIPKey],
               [theDict objectForKey: (NSString *)kABPersonAddressCountryKey]];

    _town.text = address;

    [ self dismissModalViewControllerAnimated:YES ];

        return YES;
}
return YES;
 }
4

2 に答える 2

1

NSDictionary getObjects:andKeysのドキュメント:次のように表示します:

- (void)getObjects:(id __unsafe_unretained [])objects andKeys:(id __unsafe_unretained [])keys

ただし、渡す2つの値は強力なNSString参照です(ローカル変数とivarはデフォルトで強力です。これが、ARCエラーが発生する理由です。パラメーターが予期されるタイプと一致しません。

変化する:

NSString *keys[theCount];
NSString *values[theCount];

に:

NSString * __unsafe_unretained keys[theCount];
NSString * __unsafe_unretained values[theCount];

コンパイラの問題を修正する必要があります。

この変更は、配列内のどのオブジェクトも安全に保持されないことを意味します。ただし、「theDict」が「keys」および「values」の前にスコープを超えない限り、問題はありません。

于 2012-10-13T00:04:25.073 に答える
-1

これはARCエラーであり、NSArrayをNSStringに割り当てようとしていることと、NSStringの配列を作成しようとしていることの両方で混乱していることは間違いありませんが、意図したとおりに機能するかどうかはわかりません。

後でどこで使用しているのかわかりませんが、やりたいと思います

NSArray *keys, *values;

エラーを取り除くために。

于 2012-10-13T00:04:14.777 に答える