0

Im getting the following error

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

in the following line: [theDict getObjects:values andKeys:keys]; Im trying to add an address from contacts to my app. Could someone explain to me what its complaining about? I think its an ARC issue, possibly to do with manual memory management? but im unsure how to fix it.

   - (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;
 }
JSA986
  • 5,870
  • 9
  • 45
  • 91

2 Answers2

1

The docs for NSDictionary getObjects:andKeys: show it as:

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

But the two values you are passing in are strong NSString references (local variables and ivars are strong by default. This is why there is the ARC error. Your parameters don't match the expected types.

Change:

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

to:

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

should fix the compiler issue.

This change means that none of the objects in your arrays are safely retained. But as long as 'theDict' doesn't go out scope before 'keys' and 'values' then you will be OK.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • The requirement is not only that `theDict` won't be released, but also that any key or value won't get removed or changed. – Daniel Oct 13 '12 at 00:07
  • Thank you ive been stuck on that for so long. – JSA986 Oct 13 '12 at 00:16
  • @JSA986 - You're welcome. ARC is a wonderful thing. But these sorts of cases can get sticky. BTW - why are you calling getObjects:andKeys:? The code you posted doesn't use those variables. – rmaddy Oct 13 '12 at 00:19
  • Im trying to get address details from my contacts list into my text fields in my app, i can get name and telephone number but not adress, this was tutorial code that isnt working! Still only name and numbers working! Any more advice gratefully recived – JSA986 Oct 13 '12 at 00:38
  • @JSA986 - A single contact can have more than one address. So you need to get the list of addresses first. The "Address Book Programming Guide for iOS" in the docs shows example code for getting a user's address. Have a look. – rmaddy Oct 13 '12 at 00:43
  • Thanks, already done that, thats how I've extracted the name and number. – JSA986 Oct 13 '12 at 00:48
-1

You're correct that it's an ARC error, its confused that you're trying to both assign NSArrays to NSStrings and you've tried to create an array of NSStrings, which I'm not sure will work in the way you intend.

I don't see where you're using them later, however you'll want to do

NSArray *keys, *values;

to get rid of the errors.

codewrangler
  • 350
  • 1
  • 4