Hi, I have some code that pulls the addresses from the AddressBook, and if there is one, it then gets the city. I only care about the city!
It is currently giving a warning that I can't seem to get to go away. The code *seems* to work fine on the simulator but does not work at all on the iPhone.
This is the code I am using:
Code:
ABMutableMultiValueRef addressMulti = ABRecordCopyValue(person, kABPersonAddressProperty);
NSMutableArray *address = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < ABMultiValueGetCount(addressMulti); i++) {
NSString *city = [(NSString*)ABMultiValueCopyValueAtIndex(addressMulti, i) autorelease];
[address addObject:city];
}
if ([address count] > 0) {
NSMutableDictionary *primaryAddress = [address objectAtIndex:0];
meCity1 = [primaryAddress objectForKey:kABPersonAddressCityKey];
************ WARNING: passing argument 1 of 'objectForKey:' from incompatible pointer type **********
NSLog(@"%@", meCity1);
}
meCity1 is set up earlier in the program
Any help with this would be greatly appreciated
Last edited by AlanTaylor; 07-01-2009 at 05:44 PM.
Reason: Ommission
You are missing the point. You are trying to get a list of cities from the address book right?
You are already doing that by in the first section of your code here...
Code:
ABMutableMultiValueRef addressMulti = ABRecordCopyValue(person, kABPersonAddressProperty);
NSMutableArray *address = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < ABMultiValueGetCount(addressMulti); i++) {
NSString *city = [(NSString*)ABMultiValueCopyValueAtIndex(addressMulti, i) autorelease];
[address addObject:city];
}
Why are you doing the other stuff below that. Your address array already has the cities in it? Perhaps you aren't being specific enough as to what you are trying to accomplish. The first error I pointed is that you trying to turn a string into a dictionary...which won't work.
You are missing the point. You are trying to get a list of cities from the address book right?
You are already doing that by in the first section of your code here...
Code:
ABMutableMultiValueRef addressMulti = ABRecordCopyValue(person, kABPersonAddressProperty);
NSMutableArray *address = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < ABMultiValueGetCount(addressMulti); i++) {
NSString *city = [(NSString*)ABMultiValueCopyValueAtIndex(addressMulti, i) autorelease];
[address addObject:city];
}
Why are you doing the other stuff below that. Your address array already has the cities in it? Perhaps you aren't being specific enough as to what you are trying to accomplish. The first error I pointed is that you trying to turn a string into a dictionary...which won't work.
The section of code you just quoted is actually giving me the entire address - I just want to extract the city from that.
The rest of the code checks first to see if there is an address for that person, and if there is I want it to then extract the city from that with the kABPersonAddressCityKey.
Everything else I have done with the addressbook has been single items such as names and images, this is the first time I have tried to take a value from something that has several.
EDIT: changing city to be NSMutableDictionary still gives an error - but seems to actually be working on both the Simulator and the phone...
Hi, I have some code that pulls the addresses from the AddressBook, and if there is one, it then gets the city. I only care about the city!
It is currently giving a warning that I can't seem to get to go away. The code *seems* to work fine on the simulator but does not work at all on the iPhone.
This is the code I am using:
Code:
ABMutableMultiValueRef addressMulti = ABRecordCopyValue(person, kABPersonAddressProperty);
NSMutableArray *address = [[NSMutableArray alloc] init];
int i;
for (i = 0; i < ABMultiValueGetCount(addressMulti); i++) {
NSString *city = [(NSString*)ABMultiValueCopyValueAtIndex(addressMulti, i) autorelease];
[address addObject:city];
}
if ([address count] > 0) {
NSMutableDictionary *primaryAddress = [address objectAtIndex:0];
meCity1 = [primaryAddress objectForKey:kABPersonAddressCityKey];
************ WARNING: passing argument 1 of 'objectForKey:' from incompatible pointer type **********
NSLog(@"%@", meCity1);
}
meCity1 is set up earlier in the program
Any help with this would be greatly appreciated
The compiler is being very specific in its warning. It doesn't like the argument being passed as the first parameter. So.... how is 'kABPersonAddressCityKey' defined?
The compiler is being very specific in its warning. It doesn't like the argument being passed as the first parameter. So.... how is 'kABPersonAddressCityKey' defined?
I'm guessing my code isn't setting it at all if it is just making a really long string, but I'm confused as to why this happens when the values are copied into a dictionary. This is all making me feel very stupid >.<
BSDimwit - your code worked perfectly, thank you very much for sharing it with me!