开发者

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];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜