Skip to content

Instantly share code, notes, and snippets.

View allgamesallfree's full-sized avatar
💻
Coding

Max Stein allgamesallfree

💻
Coding
View GitHub Profile
func fetch() {
// requestSampleJSON()
}
@allgamesallfree
allgamesallfree / CryptoTracker_Footer.swift
Created December 15, 2017 20:24
CryptoTracker Footer
@allgamesallfree
allgamesallfree / CryptoTracker_TableHeader.swift
Created December 15, 2017 20:20
CryptoTracker Table Header
override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
return "Cryptocurrency Prices"
}
@allgamesallfree
allgamesallfree / CryptoTracker_CellForRowAt.swift
Created December 15, 2017 20:10
CryptoTracker Cell For Row At Index Path
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let tableViewCell = tableView.dequeueReusableCell(withIdentifier: reuseIdentifier, for: indexPath)
if let cryptoTableViewCell = tableViewCell as? CryptoTableViewCell {
let currencyType = currencies[indexPath.row]
cryptoTableViewCell.formatCell(withCurrencyType: currencyType)
}
return tableViewCell
}
@allgamesallfree
allgamesallfree / CryptoTracker_NumberOfRows.swift
Created December 15, 2017 20:06
CryptoTracker Number Of Rows
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return currencies.count
}
@allgamesallfree
allgamesallfree / CryptoTracker_CurrencyInstances.swift
Created December 15, 2017 19:59
CryptoTracker Currency Instances
let currencies: [CurrencyType] = [.btc, .eth, .ltc, .xrp, .xmr, .neo]
let reuseIdentifier = String(describing: CryptoTableViewCell.self)
@allgamesallfree
allgamesallfree / CryptoTracker_FormatCell.swift
Created December 15, 2017 19:45
CryptoTracker FormatCell
func formatCell(withCurrencyType currencyType: CurrencyType) {
currencyName.text = currencyType.name
currencyImageView.image = currencyType.image
currencyType.requestValue { (value) in
DispatchQueue.main.async {
self.currencyPrice.text = value?.formattedCurrencyString ?? "Failed to get price"
}
}
@allgamesallfree
allgamesallfree / CryptoTracker_FormattedCurrencyString.swift
Last active December 20, 2017 15:31
CryptoTracker formatted currency String
private extension NSNumber {
var formattedCurrencyString: String? {
let formatter = NumberFormatter()
formatter.locale = Locale(identifier: "en_US")
formatter.numberStyle = .currency
return formatter.string(from: self)
}
}
@allgamesallfree
allgamesallfree / CryptoCurrency_URLSession.swift
Created December 15, 2017 16:15
CryptoCurrency URLSession
let request = URLSession.shared.dataTask(with: apiURL) { (data, response, error) in
// TODO: Get the data and return it
}
request.resume()
@allgamesallfree
allgamesallfree / CryptoCurrency_RequestValue1.swift
Created December 15, 2017 16:02
CryptoCurrency RequestValue1
func requestValue(completion: @escaping (_ value: NSNumber?) -> Void) {
guard let apiURL = apiURL else {
// If we couldn't serialize the JSON set the value in the completion as nil and print the error
completion(nil)
print("URL Invalid")
return
}
}