? 在Xcode 6 Beta 6中没有名为'subscript'的成员

我正在Xcode 6 Beta 6中build立一个应用程序在Swift中,我不断收到此错误:

[NSObject : AnyObject]?' does not have a member named 'subscript' 

我不知道如何解决这个问题。 我试过看这个[NSObject:AnyObject]? 在Xcode 6 beta 6中没有一个名为'subscript'错误的成员,但是我仍然不明白如何解决这个问题。 如果有人能向我解释,那将是非常好的。 如果你想看到我的代码,这里是:

 import UIKit class TimelineTableViewController: UITableViewController { override func viewDidAppear(animated: Bool) { if ((PFUser.currentUser()) != nil) { //Create an UIAlertController if there isn't an user var loginAlert:UIAlertController = UIAlertController(title: "Sign Up/ Log In", message: "Please sign up or log in", preferredStyle: UIAlertControllerStyle.Alert) //Add a textView in the Log In Alert for the username loginAlert.addTextFieldWithConfigurationHandler({ textfield in textfield.placeholder = "Your Username" }) //Add a textView in the Log In Alert for the password loginAlert.addTextFieldWithConfigurationHandler({ textfield in textfield.placeholder = "Your Password" textfield.secureTextEntry = true }) //Place the user-input into an array and set the username and password accordingly for Log In loginAlert.addAction(UIAlertAction(title: "Login", style: UIAlertActionStyle.Default, handler: { alertAction in let textFields:NSArray = loginAlert.textFields as NSArray let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField PFUser.logInWithUsernameInBackground(usernameTextfield.text, password: passwordTextfield.text){ (user:PFUser!, error:NSError!)->Void in if ((user) != nil){ println("Login successfull") }else{ println("Login failed") } } })) //Place the user-input into an array and set the username and password accordingly for Sign Up loginAlert.addAction(UIAlertAction(title: "Sign Up", style: UIAlertActionStyle.Default, handler: { alertAction in let textFields:NSArray = loginAlert.textFields as NSArray let usernameTextfield:UITextField = textFields.objectAtIndex(0) as UITextField let passwordTextfield:UITextField = textFields.objectAtIndex(1) as UITextField var sweeter:PFUser = PFUser() sweeter.username = usernameTextfield.text sweeter.password = passwordTextfield.text sweeter.signUpInBackgroundWithBlock{ (success:Bool!, error:NSError!)->Void in if !(error != nil){ println("Sign Up successfull") }else{ let errorString = error.userInfo["error"] as NSString println(errorString) } } })) } } override func viewDidLoad() { super.viewDidLoad() // Uncomment the following line to preserve selection between presentations // self.clearsSelectionOnViewWillAppear = false // Uncomment the following line to display an Edit button in the navigation bar for this view controller. // self.navigationItem.rightBarButtonItem = self.editButtonItem() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } 

这是错误发生的地方:

在这里输入图像说明

请告诉我为什么发生这种情况。 谢谢!

错误消息是说你不能在Optional值上执行[] 。 你需要做的是打开它。

 error.userInfo!["error"] as NSString 

或者如果你想要安全

 if let errorString = error.userInfo?["error"] as NSString { println(errorString) }