我想在CFSTR中传递一个变量?

时间:2011-03-28 06:45:08

标签: iphone cfstring

在下面的编码中,我想通过CFSTR传递变量,我该怎么办?

ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABDictionaryPropertyType);
// Set up keys and values for the dictionary.

CFStringRef keys[5];

CFStringRef values[5];

keys[0] = kABPersonAddressStreetKey;

keys[1] = kABPersonAddressCityKey;

keys[2] = kABPersonAddressStateKey;

keys[3] = kABPersonAddressZIPKey;

keys[4] = kABPersonAddressCountryKey;

values[0] = CFSTR("Wiztech, 208/B Clifton Center, Karachi");

//values[0] = CFSTR(address1); I want to pass address1 which is NSString, how can I?

values[1] = CFSTR("");

values[2] = CFSTR("");

values[3] = CFSTR("");

values[4] = CFSTR("");

1 个答案:

答案 0 :(得分:11)

就像投下它一样:

NSString * yourThing = [NSString stringWithString:@"blah blah"]
values[0] = (CFStringRef)yourThing;

NSString和CFString是可以互换的(可以被强制转换)。别忘了保留/释放