Cannot subscript a value

1.4k views Asked by At

I created a brand new Swift project, then added the following podfile to it

platform :ios, '8.0'
use_frameworks!

target 'LifeStream' do
pod 'SSKeychain'
pod 'LiveSDK'
pod 'Alamofire', '~> 1.2'
end

target 'LifeStreamTests' do
pod 'SSKeychain'
pod 'LiveSDK'
pod 'Alamofire', '~> 1.2'
end

I then ran pod Install which created my workspace. When it was finished, I compiled the project but received the following compiler errors in the AlamoFire framework.

Cannot subscript a value of type '[String : AnyObject]' with an index of type 'CFString!'

Cannot subscript a value of type '[String : AnyObject]' with an index of type 'CFString!'

Cannot subscript a value of type '[String : AnyObject]' with an index of type 'CFString!'

For the following code in Manager.swift

if let info = NSBundle.mainBundle().infoDictionary {
    let executable: AnyObject = info[kCFBundleExecutableKey] ?? "Unknown"
    let bundle: AnyObject = info[kCFBundleIdentifierKey] ?? "Unknown"
    let version: AnyObject = info[kCFBundleVersionKey] ?? "Unknown"

I also received several other compiler errors in the same file such as

Value of optional type 'NSURLSessionConfiguration?' not unwrapped; did you mean to use '!' or '?'?

self.session = NSURLSession(configuration: configuration, delegate: delegate, delegateQueue: nil)

Missing argument for parameter #2 in call

completionHandler(sessionDidReceiveChallenge!(session, challenge))

There are some other compiler errors in Request.swift as well. My question is, are these a result of changes made in Swift 2.0? If so, is there an ETA as to when Alamofire will have these issues fixed and published?

4

There are 4 answers

0
Johnathon Sullinger On

The answer to this was to use the new Alamofire Swift-2 branch on github. I adjusted my podfile

pod 'Alamofire', :git => 'https://github.com/Alamofire/Alamofire.git', :branch => 'swift-2.0'

and re-installed the pods. Once it was done, I was able to build the project without any issues.

0
DiegoQ On

You should update Almofire to Swift-2

You can fix those lines with this:

let executable = String(info[kCFBundleExecutableKey as String]) ?? "Unknown"
            let bundle = String(info[kCFBundleIdentifierKey as String]) ?? "Unknown"
            let version = String(info[kCFBundleVersionKey as String]) ?? "Unknown"
            let os: AnyObject = NSProcessInfo.processInfo().operatingSystemVersionString ?? "Unknown"

but I recommend that you update the library Almofire

3
Droppy On

The error messages are telling you that you're using a type that cannot be used for subscripting. kCFBundleExecutableKey and friends are CFStringRef literals. You should convert them to NSString object using

kCFBundleExecutableKey as NSString

etc.

Or you could simply use the string values they are defined as:

"CFBundleExecutable"
"CFBundleIdentifier"
"CFBundleVersion"
0
ZiggyST On

I know it's old, but you can do:

String(kCFBundleVersionKey)