-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSteamObject.swift
executable file
·62 lines (46 loc) · 2.07 KB
/
SteamObject.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// SteamObject.swift
// SteamGamesNews
//
// Created by Gemma Barrett on 02/08/2014.
// Copyright (c) 2014 Gem Barrett. All rights reserved.
//
import Foundation
class Game {
let appid: String
let name: String
let thumbnailImageURL: String
let largeImageURL: String
let playingTime: Int
init(appid: String, name: String, thumbnailImageURL: String, largeImageURL: String, playingTime: Int) {
self.name = name
self.appid = appid
self.thumbnailImageURL = thumbnailImageURL
self.largeImageURL = largeImageURL
self.playingTime = playingTime
}
class func gamesFromJSON(gameResults: NSArray) -> [Game] {
// empty array of Steam Objects to append to
var games = [Game]()
// store results in table data array
if gameResults.count > 0 {
// check for gameResults or track
for thisGame in gameResults {
let name = thisGame["name"] as! String
let appInt = thisGame["appid"] as! Int
let appid : String = "\(appInt)"
let playingTime = thisGame["playtime_forever"] as! Int
let thumbnailImageID = thisGame["img_icon_url"] as! String
let thumbnailImageURL = "http://cdn.akamai.steamstatic.com/steam/apps/\(appid)/capsule_184x69.jpg"
let largeImageID = thisGame["img_logo_url"] as! String
let largeImageURL = "http://cdn.akamai.steamstatic.com/steam/apps/\(appid)/header.jpg"
let newGame = Game(appid: appid, name: name, thumbnailImageURL: thumbnailImageURL, largeImageURL: largeImageURL, playingTime: playingTime)
games.append(newGame)
}
// sort games by playing time so most popular games at top
games = games.sorted {$0.playingTime > $1.playingTime}
}
println(games[32].appid)
return games
}
}