Skip to content

Instantly share code, notes, and snippets.

View devios1's full-sized avatar

Logan Murray devios1

View GitHub Profile
@Ben-G
Ben-G / DynamicInit.swift
Last active May 27, 2023 13:30
Dynamically create instance based on type in Swift
protocol Initializable {
init()
}
class A : Initializable {
var content:String
required init() {
content = "TestContent"
}
@shadcn
shadcn / gist:de147c42d7b3063ef7bc
Last active September 17, 2022 11:50
Convert a Hex string to UIColor in Swift
// Creates a UIColor from a Hex string.
func colorWithHexString (hex:String) -> UIColor {
var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString
if (cString.hasPrefix("#")) {
cString = cString.substringFromIndex(1)
}
if (countElements(cString) != 6) {
return UIColor.grayColor()