Skip to content

Commit deb0086

Browse files
committed
Part 7 Intro
1 parent a37c0a0 commit deb0086

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

SwiftTutorial/APIController.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class APIController: NSObject {
2222
func searchItunesFor(searchTerm: String) {
2323

2424
// The iTunes API wants multiple terms separated by + symbols, so replace spaces with + signs
25-
var itunesSearchTerm = searchTerm.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)
25+
let itunesSearchTerm = searchTerm.stringByReplacingOccurrencesOfString(" ", withString: "+", options: NSStringCompareOptions.CaseInsensitiveSearch, range: nil)
2626

2727
// Now escape anything else that isn't URL-friendly
28-
var escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
29-
var urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=music&entity=album"
30-
var url: NSURL = NSURL(string: urlPath)
31-
var session = NSURLSession.sharedSession()
32-
var task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
28+
let escapedSearchTerm = itunesSearchTerm.stringByAddingPercentEscapesUsingEncoding(NSUTF8StringEncoding)
29+
let urlPath = "https://itunes.apple.com/search?term=\(escapedSearchTerm)&media=music&entity=album"
30+
let url = NSURL(string: urlPath)
31+
let session = NSURLSession.sharedSession()
32+
let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in
3333
println("Task completed")
3434
if(error) {
3535
// If there is an error in the web request, print it to the console
@@ -41,7 +41,7 @@ class APIController: NSObject {
4141
// If there is an error parsing JSON, print it to the console
4242
println("JSON Error \(err!.localizedDescription)")
4343
}
44-
var results: NSArray = jsonResult["results"] as NSArray
44+
var results = jsonResult["results"] as NSArray
4545
// Now send the JSON result to our delegate object
4646
self.delegate?.didReceiveAPIResults(jsonResult)
4747
})

SwiftTutorial/SearchResultsViewController.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
3232
}
3333

3434
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject) {
35-
var detailsViewController: DetailsViewController = segue.destinationViewController as DetailsViewController
36-
var albumIndex = appsTableView.indexPathForSelectedRow().row
37-
var selectedAlbum = self.albums[albumIndex]
35+
let detailsViewController: DetailsViewController = segue.destinationViewController as DetailsViewController
36+
let albumIndex = appsTableView.indexPathForSelectedRow().row
37+
let selectedAlbum = self.albums[albumIndex]
3838
detailsViewController.album = selectedAlbum
3939
}
4040

4141
func tableView(tableView: UITableView!, cellForRowAtIndexPath indexPath: NSIndexPath!) -> UITableViewCell! {
4242

43-
var cell: UITableViewCell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
43+
let cell = tableView.dequeueReusableCellWithIdentifier(kCellIdentifier) as UITableViewCell
4444

4545
// Find this cell's album by passing in the indexPath.row to the subscript method for an array of type Album[]
4646
let album = self.albums[indexPath.row]
@@ -60,7 +60,7 @@ class SearchResultsViewController: UIViewController, UITableViewDataSource, UITa
6060

6161
if( !image? ) {
6262
// If the image does not exist, we need to download it
63-
let imgURL: NSURL = NSURL(string: urlString)
63+
let imgURL = NSURL(string: urlString)
6464

6565
// Download an NSData representation of the image at the URL
6666
let request: NSURLRequest = NSURLRequest(URL: imgURL)

0 commit comments

Comments
 (0)