Swift - expected expression in expression list

I'm new to Swift but don't know what that means. In the line of code below, I have the "Expected Expression in Expression List" after the [String] parameters. At the same time, he is looking for "expected", "separator". I think this is connected.

AppDelegate.submitLacunaRequest(module: "empire", method: "login", parameters[String]:["myuserid", "mypassword", "mykey"]) { responseObject, error in // some network error or programming error if error != nil { println("error = \(error)") println("responseObject = \(responseObject)") return } // network request ok, now see if login was successful if let responseDictionary = responseObject as? NSDictionary { if let errorDictionary = responseDictionary["error"] as? NSDictionary { println("error logging in (bad userid/password?): \(errorDictionary)") } else if let resultDictionary = responseDictionary["result"] as? NSDictionary { println("successfully logged in, refer to resultDictionary for details: \(resultDictionary)") } else { println("we should never get here") println("responseObject = \(responseObject)") } } } 

Here is the related code from AppDelegate

 public func submitLacunaRequest (#module: String, method: String, parameters: AnyObject, completion: (responseObject: AnyObject!, error: NSError!) -> (Void)) -> NSURLSessionTask? { let session = NSURLSession.sharedSession() let url = NSURL(string: "https://us1.lacunaexpanse.com")?.URLByAppendingPathComponent(module) let request = NSMutableURLRequest(URL: url!) request.HTTPMethod = "POST" request.setValue("application/json-rpc", forHTTPHeaderField: "Content-Type") let requestDictionary = [ "jsonrpc" : "2.0", "id" : 1, "method" : "login", "params" : ["myuserid", "mypassword", "mykey"] ] var error: NSError? let requestBody = NSJSONSerialization.dataWithJSONObject(requestDictionary, options: nil, error: &error) if requestBody == nil { completion(responseObject: nil, error: error) return nil } request.HTTPBody = requestBody let task = session.dataTaskWithRequest(request) { data, response, error in // handle fundamental network errors (eg no connectivity) if error != nil { completion(responseObject: data, error: error) return } // parse the JSON response var parseError: NSError? let responseObject = NSJSONSerialization.JSONObjectWithData(data, options: nil, error: &parseError) as? NSDictionary if responseObject == nil { // because it not JSON, let convert it to a string when we report completion (likely HTML or text) let responseString = NSString(data: data, encoding: NSUTF8StringEncoding) as String completion(responseObject: responseString, error: parseError) return } completion(responseObject: responseObject, error: nil) } task.resume() return task } 
+5
source share
2 answers

When calling a function, you use the name of the external parameter for the parameter, but the external parameter is not specified in the function declaration. Just use it that way.

submitLacunaRequest(module: "empire", "login", ["myuserid", "mypassword", "mykey"]) {

+2
source

You are calling the function incorrectly. You do not need [String] in the parameters parameters ...

 AppDelegate.submitLacunaRequest(module: "empire", method: "login", parameters: ["myuserid", "mypassword", "mykey"]) { ... } 
+1
source

Source: https://habr.com/ru/post/1213581/


All Articles