asked    Gladys     2018-07-17       ios       224 view        1 Answer

[SOLVED] Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'

I'm using Apple's Swift iOS Tutorial. Which is throwing an error,

Cannot subscript a value of type '[String : Any]' with an index of type 'UIImagePickerController.InfoKey'

The function they defined is below.

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {

    // The info dictionary may contain multiple representations of the image. You want to use the original.
    guard let selectedImage = info[UIImagePickerControllerOriginalImage] as? UIImage else {
        fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
    }

    // Set photoImageView to display the selected image.
    photoImageView.image = selectedImage

    // Dismiss the picker.
    dismiss(animated: true, completion: nil)
}

I'm using Xcode Version 10.0 beta 3, which includes Swift 4.2.

I'd like to understand how to traverse the docs to understand what might have changed or broken.

  1 Answer  

        answered    Yetta     2018-07-17      

The signature of the method has changed in Swift 4.2

func imagePickerController(_ picker: UIImagePickerController, 
  didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any])

and you have to write

guard let selectedImage = info[.originalImage] as? UIImage else {
    fatalError("Expected a dictionary containing an image, but was provided the following: \(info)")
}

You can figure out such terminology changes yourself by reading the documentation or by commenting out the entire method, retype the first few characters and use code completion.





Your Answer





 2018-07-17         Beau

[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1] when running unit tests on real device

Unit tests cannot run on device with error[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[1]App starts normally when not running unit tests and unit tests run OK in simulator for same device type and OS (iPhone 6, iOS 10.3.3). The full stack trace is* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x0000000180c79014 libsystem_kernel.dylib`__pthread_kill + 8 frame #1: 0x0000000180d43264 libsystem_pthread.dylib`pthread_kill + 112 frame #2: 0x0000000180bed9c4 libsystem_c.dylib`abort + 140 ...
 ios                     1 answers                     32 view
 2018-07-17         Benson

Could not start debugserver on “D’s iPhone” when trying to launch “Name of app”

I'm working on an iOS app, written in Swift. I try to run it on my iPhone 6S as a testing device but I get this error and I cannot figure out how to get around it:Could not start debugserver on “D’s iPhone” when trying to launch “Name of app”MacOS X is 10.13.3, Xcode 9.2 (since it's the stable version, not beta) and my iPhone runs 11.2.6 versionI tried restarting my phone, reconnecting the USB, connect via network. Nothing. It installs the app but it doesn't run it. The answer was to restart Xcode. [XXX]
 ios                     1 answers                     31 view
 2018-07-17         Abner

Xcode Native UITests very slow on real device

If I run my UITests on a simulator, they will run a lot faster, every interaction is faster somehow. Where a simulator takes about 20 seconds, a real device takes about 2 minutes.It's like I watch a sloth tap the buttons on the real device.Some info: Xcode 9.2Devices: iPhone 6 plus (iOS 10.1.1) and iPad Air (10.3.3)MacBook Pro (Retina, 15-inch, Mid 2015) with MacOS Sierra 10.12.6Swift 4Simulator: iPhone 6 (iOS 11.2)I've noticed that an iPhone 6 plus running iOS 11.2.6 runs UITests significantly faster. It is not a performance issue, it's an idling issue.Any ideas? There ...
 ios                     1 answers                     33 view