Created
August 10, 2014 01:41
-
-
Save jquave/3c355c017071889f522d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class func albumsWithJSON(allResults: NSArray) -> [Album] { | |
| // Create an empty array of Albums to append to from this list | |
| var albums = [Album]() | |
| // Store the results in our table data array | |
| if allResults.count>0 { | |
| // Sometimes iTunes returns a collection, not a track, so we check both for the 'name' | |
| for result in allResults { | |
| var name = (result["trackName"] as? String) ?? (result["collectionName"] as? String) ?? "Untitled" | |
| var priceVal = result["collectionPrice"] as? Float ?? 0.0 | |
| var price = "$???" | |
| var nf: NSNumberFormatter = NSNumberFormatter() | |
| nf.maximumFractionDigits = 2; | |
| if priceVal != nil { | |
| price = "$"+nf.stringFromNumber(priceVal) | |
| } | |
| let thumbnailURL = result["artworkUrl60"] as? String ?? "" | |
| let imageURL = result["artworkUrl100"] as? String ?? "" | |
| let artistURL = result["artistViewUrl"] as? String ?? "Unknown" | |
| var itemURL = (result["collectionViewUrl"] as? String) ?? (result["trackViewUrl"] as? String) ?? "" | |
| var collectionId = result["collectionId"] as? Int ?? 0 | |
| var newAlbum = Album(name: name, price: price, thumbnailImageURL: thumbnailURL, largeImageURL: imageURL, itemURL: itemURL, artistURL: artistURL, collectionId: collectionId) | |
| albums.append(newAlbum) | |
| } | |
| } | |
| return albums | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment