Reputation: 391
Here's my code:
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")
Missing argument for parameter "host" in call. It happens at this line.
let url = NSURL(string: "https://us1.lacunaexpanse.com").URLByAppendingPathComponent(module)
Any ideas how to solve this please?
Thanks!
Upvotes: 2
Views: 1118
Reputation: 22343
That eror is missleading. The problem isn't a missing parameter, but how you access the NSURL
. You either have to add an ?
to access the optional, because the NSURL
can be null, or you unwrap it:
//First option:
let url = NSURL(string: "https://us1.lacunaexpanse.com")?.URLByAppendingPathComponent(module)
//Unwrapping
if 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")
}
Upvotes: 2