Skip to content

Commit dc330c3

Browse files
committed
[Learn] Adding some URL Request
1 parent 8a0483d commit dc330c3

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

Day 2/day-2-swift.playground/Contents.swift

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,18 @@ print("Hello, World!")
77
func openRequest(searchTerm: String!){
88
let url = NSURL(string: "https://itunes.apple.com/search?term=\(searchTerm)&media=software")
99
let request = NSURLRequest(URL: url!)
10-
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
11-
let session = NSURLSession(configuration: config)
10+
let session = NSURLSession.sharedSession()
1211

1312
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
1413

15-
// notice that I can omit the types of data, response and error
16-
14+
do{
15+
let jsonBlob = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.AllowFragments)
16+
print(jsonBlob);
17+
}catch _ {
18+
19+
}
1720
// your code
18-
print(data);
21+
1922

2023
});
2124

0 commit comments

Comments
 (0)