简体   繁体   中英

(NSObject, AnyObject) is not convertible to DictionaryIndex<NSObject, AnyObject>

I was working on converting this delegate protocol function from an Objective-C tutorial, but ran into an error trying to access the values in a dictionary by using the subscript to return the value based on the key. I am not quite sure what the error here means. Any help would be greatly appreciated!

// Sent to the delegate to determine whether the sign up request should be submitted to the server
func signUpViewController(signUpController: PFSignUpViewController!, shouldBeginSignUp info: [NSObject : AnyObject]!) -> Bool {
  var informationComplete: Bool = true

  // Loop through all of the submitted data
  for key in info {
    var field: String = info[key] // Error occurs at this line on info
    if field.isEmpty {
      informationComplete = false
      break
    }
  }

  // Display an alert if a field was not completed
  if !informationComplete {
    let alertView: UIAlertView = UIAlertView(title: "Missing Information", message: "Please make sure all information is filled out!", delegate: nil, cancelButtonTitle: "ok")
  }

  return informationComplete
}

You did not post your declaration. But likely you can solve it with:

for (key, field) in info {
  if field.isEmpty {
    informationComplete = false
    break
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM