Skip to content

Instantly share code, notes, and snippets.

@towry
Created June 21, 2017 01:52
Show Gist options
  • Save towry/0c780e49c52b543b532954f1651ce343 to your computer and use it in GitHub Desktop.
Save towry/0c780e49c52b543b532954f1651ce343 to your computer and use it in GitHub Desktop.
swift: request a web page.
//: Playground - noun: a place where people can play
import Foundation
import PlaygroundSupport
URLCache.shared = URLCache(memoryCapacity: 0, diskCapacity: 0, diskPath: nil)
let url = URL(string: "http://www.baidu.com")
let task = URLSession.shared.dataTask(with: url!) {data, response, error in
guard let data = data, error == nil else { return }
print(NSString(data: data, encoding: String.Encoding.utf8.rawValue))
}
#if ABC
print("hahahahah")
#endif
print("begin")
task.resume()
PlaygroundPage.current.needsIndefiniteExecution = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment