在Swift 1.2之前,我有以下数组:
private let phoneLabels = [
kABPersonPhoneMobileLabel,
kABPersonPhoneIPhoneLabel,
kABWorkLabel,
kABHomeLabel,
kABPersonPhoneMainLabel,
kABPersonPhoneHomeFAXLabel,
kABPersonPhoneWorkFAXLabel,
kABPersonPhonePagerLabel,
kABOtherLabel
] as [String]
在我将Xcode更新为6.3后,我不能这样:
private let phoneLabels = [
kABPersonPhoneMobileLabel,
kABPersonPhoneIPhoneLabel,
kABWorkLabel,
kABHomeLabel,
kABPersonPhoneMainLabel,
kABPersonPhoneHomeFAXLabel,
kABPersonPhoneWorkFAXLabel,
kABPersonPhonePagerLabel,
kABOtherLabel
] as! [String]
因为编译器向我显示错误:'[CFString!]' is not convertible to '[String]'
。
我可以将数组中的每个CFString
转换为String
,但也许有一种更简单,更易读的方法来修复它?
答案 0 :(得分:3)
像这样:
private let phoneLabels = [
kABPersonPhoneMobileLabel,
kABPersonPhoneIPhoneLabel,
kABWorkLabel,
kABHomeLabel,
kABPersonPhoneMainLabel,
kABPersonPhoneHomeFAXLabel,
kABPersonPhoneWorkFAXLabel,
kABPersonPhonePagerLabel,
kABOtherLabel
] as [AnyObject] as! [String]