2016-10-02 3 views
-1

erhielt ich zwei Fehler aus dem Skript unten:erwartet '' seperator und erwartete ')' in Ausdruck Liste

 request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) 



     let task = NSURLSession.sharedSession().dataTaskWithRequest(request){ 
      data, response, error in 

      if error != nil { 
       print("error=\(error)") 
       return 
      } 
      do { 
       if let parseJSON = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary { 
        print(parseJSON) 

        let resultValue:String = parseJSON["status"] as! String 
        print("Result: \(resultValue)") 
        print(userEmail) 
        print(userPassword) 


        var isUserRegistered:Bool = false; 
        if(resultValue=="Success") { isUserRegistered = true; } 

        var messageToDisplay:String = parseJSON["message"] as! String!; 
        if(!isUserRegistered) 
        { 
         messageToDisplay = parseJSON["message"] as! String!; 
        } 

        dispatch_async(dispatch_get_main_queue(), { 

         //Display alert message with confirmation 
         let myAlert = UIAlertController(title: "Alert", message:messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert); 

         let okAction = UIAlertAction(title:"Alert", style:UIAlertActionStyle.Default){ 

          action in self.dismissViewControllerAnimated(true, completion:nil); 

         } 

         myAlert.addAction(okAction) 
         self.presentViewController(myAlert, animated:true, completion:nil); 
         )}; 
       } 
      } 
     catch let error as NSError { 
       print(error.localizedDescription) 
      } 

     } 

     task.resume() 

    } 

} 

Der erste Fehler war: Expected ',' seperator auf dieser Linie:

)}; 

Es sagt zu insert ",", aber es ist ein kontinuierlicher Fehler und es endet nicht.

In der nächsten Zeile unten, die } nur eine Klammer ist, erhalte ich die Fehlermeldung: Expected ')' in the expression list

+1

Sie wollen '})', nicht ')}' (oder Sie könnten die abschließende Closure-Syntax verwenden). Beachten Sie auch, dass Sie keine Semikolons am Ende der Zeilen oder Klammern um Ihre 'if'-Bedingungen benötigen. – Hamish

+1

Swift ist ** nicht * eine * Skriptsprache * (im Gegensatz zu PHP) ;-) – vadian

Antwort

2

}) nicht)}

request.HTTPBody = postString.dataUsingEncoding(NSUTF8StringEncoding) 



    let task = NSURLSession.sharedSession().dataTaskWithRequest(request){ 
     data, response, error in 

     if error != nil { 
      print("error=\(error)") 
      return 
     } 
     do { 
      if let parseJSON = try NSJSONSerialization.JSONObjectWithData(data!, options: []) as? NSDictionary { 
       print(parseJSON) 

       let resultValue:String = parseJSON["status"] as! String 
       print("Result: \(resultValue)") 
       print(userEmail) 
       print(userPassword) 


       var isUserRegistered:Bool = false; 
       if(resultValue=="Success") { isUserRegistered = true; } 

       var messageToDisplay:String = parseJSON["message"] as! String!; 
       if(!isUserRegistered) 
       { 
        messageToDisplay = parseJSON["message"] as! String!; 
       } 

       dispatch_async(dispatch_get_main_queue(), { 

        //Display alert message with confirmation 
        let myAlert = UIAlertController(title: "Alert", message:messageToDisplay, preferredStyle: UIAlertControllerStyle.Alert); 

        let okAction = UIAlertAction(title:"Alert", style:UIAlertActionStyle.Default){ 

         action in self.dismissViewControllerAnimated(true, completion:nil); 

        } 

        myAlert.addAction(okAction) 
        self.presentViewController(myAlert, animated:true, completion:nil); 
       }); 
      } 
     } 
     catch let error as NSError { 
      print(error.localizedDescription) 
     } 

    } 

    task.resume() 

} 

} 
Verwandte Themen