iphone - 将字符串与 ABPropertyID 匹配

标签 iphone objective-c ios

我现在正在使用 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/

相关文章:

ios - 在 objective-c 中获得正整数值

Objective-C int 桥接为 Int32 到 Swift

ios - 从 [Entity] 转换为无关类型的 Entity 在 CoreData 中总是失败

iOS7 : What is the best way to give the user the ability to choose between taking a photo and going to a photo gallery?

iphone - 我应该使用什么 OSX/XCode 版本控制系统来进行 iPhone 开发?

iPhone sdk,忽略模拟器中的代码?

objective-c - Cocoa 的 JSON 解析器

ios - 如何将圆形 UIButton 的 UIControlEventTouchUpInside 限制在圆圈内?

ios - 如何启用和禁用越狱 iOS 设备的 WiFi 连接?

iphone - UIImage绘制矩形:rect is too slow