in visual basic I upload html page as a string like this ..
system.net.webclient (). downloadstring ("http://example.com")
How do I download the html page for a swift in xcode ios?
in visual basic I upload html page as a string like this ..
system.net.webclient (). downloadstring ("http://example.com")
How do I download the html page for a swift in xcode ios?
In Swift 1.2 (Xcode 6.4):
func htmlStringFromURL(url: NSURL) -> String?
{
var encoding: UInt = 0
let html = NSString(contentsOfURL: url, usedEncoding: &encoding, error:nil)
return html as? String
}
let x = htmlStringFromURL(NSURL(string: "http://www.apple.com")!)
In Swift 2.0 (Xcode 7 beta)
func htmlStringFromURL(url: NSURL) -> String?
{
do
{
var encoding: UInt = 0
let html = try NSString(contentsOfURL: url, usedEncoding: &encoding)
return html as String
}
catch {return nil}
}
let x = htmlStringFromURL(NSURL(string: "http://www.apple.com")!)