Skip to content

Instantly share code, notes, and snippets.

View allgamesallfree's full-sized avatar
💻
Coding

Max Stein allgamesallfree

💻
Coding
View GitHub Profile
//A few basic UIColor's
let red = UIColor(red: 255/255, green: 0, blue: 0, alpha: 1.0)
let darkGrey = UIColor(red: 100/255, green: 100/255, blue: 100/255, alpha: 1.0)
let cyan = UIColor(red: 0, green: 255/255, blue: 255/255, alpha: 1.0)
let red = UIColor(r: 255, g: 0, b: 0, alpha: 1.0)
let darkGrey = UIColor(r: 100, g: 100, b: 100, alpha: 1.0)
let cyan = UIColor(r: 0, g: 255, b: 255, alpha: 1.0)
convenience init(r: Int, g: Int, b: Int, alpha: CGFloat = 1.0) {
let red = CGFloat(r)/255
let green = CGFloat(g)/255
let blue = CGFloat(b)/255
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
import UIKit
extension UIColor {
convenience init(r: Int, g: Int, b: Int, alpha: CGFloat) {
let red = CGFloat(r)/255
let green = CGFloat(g)/255
let blue = CGFloat(b)/255
self.init(red: red, green: green, blue: blue, alpha: alpha)
}
convenience init(r: Int, g: Int, b: Int, alpha: CGFloat = 1.0) {
func intToColorFloat(int: Int) -> CGFloat {
let divisor: CGFloat = 255
return CGFloat(int) / divisor
}
self.init(red: intToColorFloat(r), green: intToColorFloat(g), blue: intToColorFloat(b), alpha: alpha)
}
let red = UIColor(r: 255, g: 0, b: 0)
let darkGrey = UIColor(r: 100, g: 100, b: 100)
let cyan = UIColor(r: 0, g: 255, b: 255)
@allgamesallfree
allgamesallfree / CryptoTracker_URL.swift
Created September 24, 2017 01:18
CryptoTracker URL
let apiURL = URL(string: "https://min-api.cryptocompare.com/data/pricehistorical?fsym=ETH&tsyms=USD")
@allgamesallfree
allgamesallfree / CryptoTracker_InitialAPI.swift
Last active September 24, 2017 01:20
CryptoTracker_InitialAPI
private func makeValueGETRequest(url: URL, completion: @escaping (_ value: NSNumber?) -> Void) {
let request = URLSession.shared.dataTask(with: url) { (data, response, error) in
// TODO: Get the data and return it
}
request.resume()
}
guard let data = data, error == nil else {
completion(nil)
print(error?.localizedDescription ?? "")
return
}
@allgamesallfree
allgamesallfree / CryptoTracker_FormatCurrency.swift
Last active September 24, 2017 02:31
CryptoTracker Format Currency
private func formatAsCurrencyString(value: NSNumber?) -> String? {
let formatter = NumberFormatter()
formatter.locale = Locale(identifier: "en_US")
formatter.numberStyle = .currency
// TODO: Unwrap the number as a formatted currency String
}