Olyve
Olyve

Reputation: 731

(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
}

Upvotes: 0

Views: 481

Answers (1)

qwerty_so
qwerty_so

Reputation: 36305

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

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

Upvotes: 3

Related Questions