Reputation: 2681
This is sample code. I have an error in string:
var theReply = String.stringWithBytes(GETReply.bytes, length: GETReply.length, encoding: NSASCIIStringEncoding)
Error:
Could not find an overload for '_conversion' that accepts the supplied arguments
What is wrong?
@IBAction func loginButton(sender: AnyObject) {
if !loginL.text.isEmpty || !passL.text.isEmpty {
var request:NSMutableURLRequest = NSMutableURLRequest()
var login = loginL.text.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
var pass = passL.text.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
var stringURL = "http://nakhimov.info/iosdev/user.php?t=1&l=\(login)&p=\(pass)"
NSLog("URL string for login: \(stringURL)")
var webURL = stringURL.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
request.URL = NSURL.URLWithString(webURL)
request.HTTPMethod = "GET"
request.setValue("application/json;charset=UTF-8", forHTTPHeaderField: "Content-Type")
var responce:NSURLResponse?
let GETReply:NSData = NSURLConnection.sendSynchronousRequest(request, returningResponse: &responce, error: nil)
var theReply = String.stringWithBytes(GETReply.bytes, length: GETReply.length, encoding: NSASCIIStringEncoding)
var wrong = "ERROR"
if theReply == wrong {
myAlertShow("ERROR!", message: "Login or password is invalid")
}
else {
self.performSegueWithIdentifier("closeZoneSegue", sender: self)
}
}
resetToDefaults()
}
Upvotes: 0
Views: 387
Reputation: 2681
Solved! :-)
var theReply = NSString(bytes: GETReply.bytes, length: GETReply.length, encoding: NSASCIIStringEncoding)
Upvotes: 1