Shmidt
Shmidt

Reputation: 16664

'[CFString!]' is not convertible to '[String]'

Before Swift 1.2 I had following array:

private let phoneLabels = [
    kABPersonPhoneMobileLabel,
    kABPersonPhoneIPhoneLabel,
    kABWorkLabel,
    kABHomeLabel,
    kABPersonPhoneMainLabel,
    kABPersonPhoneHomeFAXLabel,
    kABPersonPhoneWorkFAXLabel,
    kABPersonPhonePagerLabel,
    kABOtherLabel
] as [String]

After I updated Xcode to 6.3, I can't have it like that:

private let phoneLabels = [
    kABPersonPhoneMobileLabel,
    kABPersonPhoneIPhoneLabel,
    kABWorkLabel,
    kABHomeLabel,
    kABPersonPhoneMainLabel,
    kABPersonPhoneHomeFAXLabel,
    kABPersonPhoneWorkFAXLabel,
    kABPersonPhonePagerLabel,
    kABOtherLabel
] as! [String]

Because compiler shows me an error: '[CFString!]' is not convertible to '[String]'.

I can probably convert each CFString to String in array, but maybe there is an easier and more readable way to fix that?

Upvotes: 2

Views: 1548

Answers (1)

matt
matt

Reputation: 535222

Like this:

private let phoneLabels = [
    kABPersonPhoneMobileLabel,
    kABPersonPhoneIPhoneLabel,
    kABWorkLabel,
    kABHomeLabel,
    kABPersonPhoneMainLabel,
    kABPersonPhoneHomeFAXLabel,
    kABPersonPhoneWorkFAXLabel,
    kABPersonPhonePagerLabel,
    kABOtherLabel
] as [AnyObject] as! [String]

Upvotes: 3

Related Questions