Skip to content

Instantly share code, notes, and snippets.

@nbasham
nbasham / ThreadUtil.swift
Last active January 29, 2016 23:21
Run a block on the main thread after a specified number of seconds.
import Foundation
public class ThreadUtil : NSObject {
// Run a block on the main thread after a specified number of seconds, thanks raywenderlich.com for splaining it so well
public static func runOnMainThreadAfterDelay(delaySeconds: Double, closure: () -> ()) {
let startTime = dispatch_time(DISPATCH_TIME_NOW, Int64(delaySeconds * Double(NSEC_PER_SEC)))
dispatch_after(startTime, dispatch_get_main_queue(), closure)
}
@nbasham
nbasham / UIColor.swift
Last active December 18, 2023 21:04
Swift 4: Convert CSS color names and RGB hex values to UIColor. UIColor from hex 3, 4, 6, and 8 characters in length with or without # prefix. UIColor to hex. UIColor extension that creates immutable UIColor instances from hexadecimal and CSS color name strings (e.g. ff0, #f00, ff0000, ff0000ff, Pink, aZure, CLEAR, nil). Conversely, you can obta…
//
// UIColor.swift
// previously Color+HexAndCSSColorNames.swift
//
// Created by Norman Basham on 12/8/15.
// Copyright ©2018 Black Labs. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights