@@ -15,10 +15,9 @@ class SearchResultsViewController: UIViewController,/* UITableViewDataSource, UI
15
15
var api : APIController = APIController ( )
16
16
@IBOutlet var appsTableView : UITableView
17
17
18
- var tableData : Dictionary < String , AnyObject > [ ] = [ ]
19
18
var albums : Album [ ] = [ ]
20
-
21
- var imageCache = NSMutableDictionary ( )
19
+ //var imageCache = NSMutableDictionary()
20
+ var imageCache = Dictionary < String , UIImage > ( )
22
21
23
22
override func viewDidLoad( ) {
24
23
super. viewDidLoad ( )
@@ -48,25 +47,16 @@ class SearchResultsViewController: UIViewController,/* UITableViewDataSource, UI
48
47
}
49
48
50
49
func tableView( tableView: UITableView ! , numberOfRowsInSection section: Int ) -> Int {
51
- //return countElements(self.tableData)
52
- //return self.tableData.count
53
50
return albums. count
54
51
}
55
52
56
53
57
54
func tableView( tableView: UITableView ! , cellForRowAtIndexPath indexPath: NSIndexPath ! ) -> UITableViewCell ! {
58
55
59
-
60
-
61
56
var cell : UITableViewCell = tableView. dequeueReusableCellWithIdentifier ( kCellIdentifier) as UITableViewCell
62
- if cell == nil {
63
- cell = UITableViewCell ( style: UITableViewCellStyle . Subtitle, reuseIdentifier: kCellIdentifier)
64
- }
65
57
66
- var index : Int = indexPath. row
67
-
68
- // Find this cell's album by passing in the Int 'index' to the subscript method for an array of type Album[]
69
- var album = self . albums [ index]
58
+ // Find this cell's album by passing in the indexPath.row to the subscript method for an array of type Album[]
59
+ let album = self . albums [ indexPath. row]
70
60
71
61
cell. text = album. title
72
62
cell. image = UIImage ( named: " Blank52 " )
@@ -78,24 +68,24 @@ class SearchResultsViewController: UIViewController,/* UITableViewDataSource, UI
78
68
79
69
// Grab the artworkUrl60 key to get an image URL for the app's thumbnail
80
70
//var urlString: NSString = rowData["artworkUrl60"] as NSString
81
- var urlString = album. thumbnailImageURL
71
+ let urlString = album. thumbnailImageURL
82
72
83
73
// Check our image cache for the existing key. This is just a dictionary of UIImages
84
- var image : UIImage ? = self . imageCache. valueForKey ( urlString) as? UIImage
74
+ var image : UIImage ? = self . imageCache [ urlString! ]
85
75
86
76
if ( !image? ) {
87
77
// If the image does not exist, we need to download it
88
- var imgURL : NSURL = NSURL ( string: urlString)
78
+ let imgURL : NSURL = NSURL ( string: urlString)
89
79
90
80
// Download an NSData representation of the image at the URL
91
- var request : NSURLRequest = NSURLRequest ( URL: imgURL)
92
- var urlConnection : NSURLConnection = NSURLConnection ( request: request, delegate: self )
81
+ let request : NSURLRequest = NSURLRequest ( URL: imgURL)
82
+ let urlConnection : NSURLConnection = NSURLConnection ( request: request, delegate: self )
93
83
NSURLConnection . sendAsynchronousRequest ( request, queue: NSOperationQueue . mainQueue ( ) , completionHandler: { ( response: NSURLResponse!, data: NSData!, error: NSError!) - > Void in
94
84
if !error? {
95
85
image = UIImage ( data: data)
96
86
97
87
// Store the image in to our cache
98
- self . imageCache. setValue ( image , forKey : urlString )
88
+ self . imageCache [ urlString! ] = image
99
89
100
90
// Sometimes this request takes a while, and it's possible that a cell could be re-used before the art is done loading.
101
91
// Let's explicitly call the cellForRowAtIndexPath method of our tableView to make sure the cell is not nil, and therefore still showing onscreen.
@@ -125,7 +115,7 @@ class SearchResultsViewController: UIViewController,/* UITableViewDataSource, UI
125
115
// Store the results in our table data array
126
116
if results. count> 0 {
127
117
128
- var allResults : NSDictionary [ ] = results [ " results " ] as NSDictionary [ ]
118
+ let allResults : NSDictionary [ ] = results [ " results " ] as NSDictionary [ ]
129
119
130
120
// var swiftResultArray: NSDictionary[] = allResults
131
121
@@ -152,10 +142,9 @@ class SearchResultsViewController: UIViewController,/* UITableViewDataSource, UI
152
142
}
153
143
}
154
144
155
- var thumbnailURL : String ? = result [ " artworkUrl60 " ] as? String
156
- var imageURL : String ? = result [ " artworkUrl100 " ] as? String
157
-
158
- var artistURL : String ? = result [ " artistViewUrl " ] as? String
145
+ let thumbnailURL : String ? = result [ " artworkUrl60 " ] as? String
146
+ let imageURL : String ? = result [ " artworkUrl100 " ] as? String
147
+ let artistURL : String ? = result [ " artistViewUrl " ] as? String
159
148
160
149
var itemURL : String ? = result [ " collectionViewUrl " ] as? String
161
150
if !itemURL? {
0 commit comments