ios - NSData is not a subtype of NSData? -
i geting error:
nsdata not subtype of nsdata code below, doing wrong?
let urlpath = "myurl" var url = nsurl(string: urlpath) allow session = nsurlsession.sharedsession() allow task = session.datataskwithrequest(url, completionhandler: {data, response, error -> void in if error { println(error) } else { println(data) } }) task.resume()
the actual error message 'nsdata!' not subtype of 'nsdata'
(notice ! after nsdata
)
nsurl(string:)
failable initializer, new in swift 1.1 (xcode 6.1). failable initializers homecoming optional nil
upon failure.
you must check failure before can utilize url:
let urlpath = "myurl" if allow url = nsurl(string: urlpath) { allow session = nsurlsession.sharedsession() allow request = nsurlrequest(url: url) allow task = session.datataskwithrequest(request, completionhandler: {data, response, error -> void in if error != nil { println(error) } else { println(data) } }) task.resume() }
ios xcode swift
No comments:
Post a Comment