“[CFString!]”不能转换为“[String]”
'[CFString!]' is not convertible to '[String]'
在 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
,但也许有更简单、更易读的方法来解决这个问题?
像这样:
private let phoneLabels = [
kABPersonPhoneMobileLabel,
kABPersonPhoneIPhoneLabel,
kABWorkLabel,
kABHomeLabel,
kABPersonPhoneMainLabel,
kABPersonPhoneHomeFAXLabel,
kABPersonPhoneWorkFAXLabel,
kABPersonPhonePagerLabel,
kABOtherLabel
] as [AnyObject] as! [String]
在 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
,但也许有更简单、更易读的方法来解决这个问题?
像这样:
private let phoneLabels = [
kABPersonPhoneMobileLabel,
kABPersonPhoneIPhoneLabel,
kABWorkLabel,
kABHomeLabel,
kABPersonPhoneMainLabel,
kABPersonPhoneHomeFAXLabel,
kABPersonPhoneWorkFAXLabel,
kABPersonPhonePagerLabel,
kABOtherLabel
] as [AnyObject] as! [String]