ABPr-6ren">
gpt4 book ai didi

iphone - 将字符串与 ABPropertyID 匹配

转载 作者:行者123 更新时间:2023-11-29 04:57:03 24 4
gpt4 key购买 nike

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com