我现在正在使用 AddressBook,需要将 ABPropertyID 的字符串表示形式转换(匹配)为 ABPropertyID:
@"kABPersonEmailProperty" -> ABPropertyID kABPersonEmailProperty;
我可以在不使用 ifs 的情况下灵活地实现它吗?
最佳答案
Can I do it flexible without using ifs?
不是真的。最简单的方法可能是在两者之间映射的代码中手动准备一个 NSDictionary
。没有办法完全自动地执行此操作,因为常量的名称不是编译程序的一部分。
示例:
NSDictionary *mapping = [NSDictionary dictionaryWithObjectsAndKeys:
@"kABPersonEmailProperty", [NSNumber numberWithInteger:kABPersonEmailProperty],
@"kABPersonEmailProperty", [NSNumber numberWithInteger:kABPersonBirthdayProperty],
nil];
关于iphone - 将字符串与 ABPropertyID 匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7752554/