View gist:58802c851a8269c818707fc63f29cb54
This file contains 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
import SwiftUI | |
public enum Enum1: Int, Codable, CaseIterable, CustomStringConvertible { | |
public var description: String { | |
return "\(rawValue)" | |
} | |
case one, two, three | |
} | |
public enum Enum2: String, Codable, CaseIterable, CustomStringConvertible { |
View CodeTimer.swift
This file contains 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
import Foundation | |
class CodeTimer { | |
var startTime: CFAbsoluteTime = 0 | |
init() { start() } | |
func start() { startTime = CFAbsoluteTimeGetCurrent() } | |
func log(_ message: String) { | |
let timeElapsed = CFAbsoluteTimeGetCurrent() - startTime |
View Data+Extensions.swift
This file contains 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
import Foundation | |
extension Date { | |
static func randomBetween(start: String, end: String, format: String = "yyyy-MM-dd") -> String { | |
let date1 = Date.parse(start, format: format) | |
let date2 = Date.parse(end, format: format) | |
return Date.randomBetween(start: date1, end: date2).dateString(format) | |
} |
View UIView
This file contains 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
import UIKit | |
public extension UIView { | |
public var top: CGFloat { | |
get { return self.frame.origin.y } | |
set { self.frame.origin.y = newValue } | |
} | |
public var left: CGFloat { | |
get { return self.frame.origin.x } |
View Sequence
This file contains 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
public extension Sequence { | |
// return true if all elements return true | |
func every<T>(predicate:(T) -> Bool) -> Bool { | |
for item in self { | |
if !predicate(item as! T) { | |
return false | |
} | |
} | |
return true |
View gist:c6af488949dc3435e43b3d3cba9d4df4
This file contains 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
import UIKit | |
import PlaygroundSupport | |
public class DeviceViewController : UIViewController { | |
public enum ScreenType : Int { | |
case iPhone3_5Inch | |
case iPhone4Inch // includes 5th & 6h gen iPod Touch | |
case iPhone4_7Inch | |
case iPhone5_5Inch |
View StoreKitUtil.swift
This file contains 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
import StoreKit | |
public extension SKProduct { | |
convenience init(d : Dictionary<String, AnyObject>) { | |
self.init() | |
self.setValue(d["uid"], forKey: "productIdentifier") | |
self.setValue(d["title"], forKey: "localizedTitle") | |
self.setValue(d["detail"], forKey: "localizedDescription") | |
self.setValue(NSDecimalNumber(string: (d["price"] as! String?)), forKey: "price") |
View Array
This file contains 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
import UIKit | |
public extension Sequence { | |
// return true if all elements return true | |
func every<T>(predicate:(T) -> Bool) -> Bool { | |
for item in self { | |
if !predicate(item as! T) { | |
return false | |
} |
View IOSDirectoryFile
This file contains 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
import Foundation | |
protocol IOSDirectoryFile { | |
static var dirSelector: FileManager.SearchPathDirectory { get } | |
} | |
extension IOSDirectoryFile { | |
static var url: URL { | |
return FileManager.default.urls(for: dirSelector, in: .userDomainMask)[0] |
NewerOlder