Match String to ABPropertyID
I'm working now with the AddressBook and I need to convert(match) the String representation of ABPropertyID to ABPro开发者_Python百科pertyID:
@"kABPersonEmailProperty" -> ABPropertyID kABPersonEmailProperty;
Can I do it flexible without using ifs?
Can I do it flexible without using ifs?
Not really. The easiest way is probably to manually prepare an NSDictionary
in code that maps between the two. There is no way to do this entirely automatically because the names of the constants are not part of the compiled program.
Example:
NSDictionary *mapping = [NSDictionary dictionaryWithObjectsAndKeys:
@"kABPersonEmailProperty", [NSNumber numberWithInteger:kABPersonEmailProperty],
@"kABPersonEmailProperty", [NSNumber numberWithInteger:kABPersonBirthdayProperty],
nil];
精彩评论