Skip to content

Instantly share code, notes, and snippets.

View allgamesallfree's full-sized avatar
💻
Coding

Max Stein allgamesallfree

💻
Coding
View GitHub Profile
@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
}
@allgamesallfree
allgamesallfree / CryptoTracker_FormatCurrency2.swift
Created October 6, 2017 00:58
CryptoTracker_FormatCurrency2
guard let value = value,
let formattedCurrencyAmount = formatter.string(from: value) else {
return nil
}
return formattedCurrencyAmount
guard let apiURL = apiURL else {
return
}
makeValueGETRequest(url: apiURL) { (value) in
DispatchQueue.main.async {
self.etherValueLabel.text = self.formatAsCurrencyString(value: value) ?? "Failed"
}
}
@allgamesallfree
allgamesallfree / ScreenType.swift
Last active October 16, 2017 02:00
Get iOS Screen Type
@objc enum ScreenType: Int {
case iPhone4, iPhone5, iPhone6, iPhone6Plus, iPhoneX, iPad9_7, iPad10_5, iPad12_9
}
extension UIScreen {
@objc static var current: ScreenType {
let screenLongestSide: CGFloat = {
let screenBounds = main.bounds
if screenBounds.height > screenBounds.width {
return screenBounds.height
@allgamesallfree
allgamesallfree / ScreenType_Comparison1.swift
Last active October 25, 2017 16:46
Compare current Screen Type in iOS
if UIScreen.current == .iPhone5_8 {
print("Screen type is iPhone X")
}
@allgamesallfree
allgamesallfree / ScreenType_Comparison2.swift
Last active October 25, 2017 16:45
Compare two screen types to current iOS device screen
if UIScreen.current == .iPhone4_7 || UIScreen.current == .iPhone5_5 {
print("Screen type is either iPhone 6/7/8 or 6/7/8 Plus")
}
@allgamesallfree
allgamesallfree / ScreenType_Comparison3.swift
Last active October 25, 2017 16:43
Compare if iOS screen type is above or below a particular model
if UIScreen.current < .iPhone4_7 {
print("Screen is smaller than an iPhone 6/7/8")
}
if UIScreen.current >= .iPad10_5 {
print("Screen type is either iPad 10.5 or iPad 12.9")
}
@allgamesallfree
allgamesallfree / ScreenType_ObjC1.m
Last active October 25, 2017 16:45
Compare if iOS screen type is iPhone X in Objective-C
if ([UIScreen current] == ScreenTypeIPhone5_8) {
NSLog(@"Screen Type is iPhone X");
}
@allgamesallfree
allgamesallfree / ScreenType_ObjC2.m
Last active October 25, 2017 16:44
Compare if iOS Screen is larger than an iPhone 5
if ([UIScreen current] > ScreenTypeIPhone4_0) {
NSLog(@"Screen is larger than an iPhone 5/5S/5C");
}