|
ToDo:
|
Swift3だと色々変わってくれるね。
import PlaygroundSupportしてPlaygroundPage.current.needsIndefiniteExecution = trueなのね。
import UIKit
import Foundation
import PlaygroundSupport
var urlString = "http://ajax.googleapis.com/ajax/services/feed/load?v=1.0&q=http://rss.dailynews.yahoo.co.jp/fc/rss.xml&num=8"
var url = NSURL(string: urlString)
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let task = session.dataTask(with: url! as URL,
completionHandler:
{data, response, error in
do{
var dict = try JSONSerialization.jsonObject(with: data!, options: JSONSerialization.ReadingOptions.mutableContainers)
print(dict)
}
catch{}
})
task.resume()
PlaygroundPage.current.needsIndefiniteExecution = true
import UIKit
import Foundation
import PlaygroundSupport
var urlString = "http://www.apple.com"
var url = NSURL(string: urlString)
var request = NSURLRequest(url: url! as URL)
let config = URLSessionConfiguration.default
let session = URLSession(configuration: config)
let task = session.dataTask(with: url! as URL,
completionHandler: {data, response, error in
print(NSString(data: data!,encoding: String.Encoding.utf8.rawValue))
})
task.resume()
PlaygroundPage.current.needsIndefiniteExecution = true
このPageあたりをヒントに前に作ったコードを修正してみる。