Skip to content

Instantly share code, notes, and snippets.

View robnadin's full-sized avatar

Rob Nadin robnadin

  • Dyson
  • Bristol, UK
  • 18:11 (UTC +01:00)
  • X @robnadin
View GitHub Profile
extension UINavigationController {
func pushViewController(_ viewController: UIViewController, animated: Bool, completionHandler: (() -> Void)?) {
pushViewController(viewController, animated: animated)
viewController.transitionCoordinator.animate(alongsideTransition: nil) { _ in
completionHandler?()
}
}
}
@robnadin
robnadin / NSAttributedString+HTMLStyle.h
Last active May 29, 2019 04:56
NSAttributedString-HTMLStyle
//
// NSAttributedString+HTMLStyle.h
// QRContentMobilizer
//
// Created by Wojciech Czekalski on 22.03.2014.
// Copyright (c) 2014 Wojciech Czekalski. All rights reserved.
//
#import <Foundation/Foundation.h>
@robnadin
robnadin / NSDate+ISO8601.swift
Created March 8, 2016 16:44
Fast C-based ISO8601 date parser written in Swift
import Foundation
extension NSDate {
class func dateFromISO8601String(string: String?) -> NSDate? {
guard let string = string else {
return nil
}
var tm = Darwin.tm()
@robnadin
robnadin / Optional+BooleanType.swift
Created March 23, 2016 16:06
Ternary operator support for optionals
extension Optional: BooleanType {
public var boolValue: Bool {
switch self {
case .Some(let value) where !(value is Bool):
return true
case .Some(let value as Bool) where value:
return true
default:
return false
import UIKit
extension UIResponder {
private weak static var _currentFirstResponder: UIResponder?
static var currentFirstResponder: UIResponder? {
get {
_currentFirstResponder = nil
UIApplication.sharedApplication().sendAction(#selector(findFirstResponder), to: nil, from: nil, forEvent: nil)
extension NSUUID {
static var zero: NSUUID {
var bytes = [UInt8](count: 16, repeatedValue: 0)
return NSUUID(UUIDBytes: &bytes)
}
}
Pod::Spec.new do |s|
s.name = 'BLEFramework'
s.version = '1.4'
s.summary = 'The Buzz Flashing Glassware framework allows you to activate your Buzz Celebration Drinkware from your mobile device.'
s.homepage = 'http://www.buzzproducts.com/flashingcup/'
s.author = { 'Buzz Products' => '[email protected]' }
s.source = { :path => 'BLEFramework' }
s.social_media_url = 'https://twitter.com/buzzproducts'
s.ios.deployment_target = '8.0'
@robnadin
robnadin / HashTable.swift
Created October 31, 2016 08:30
A generic wrapper for NSHashTable on Swift <= 2.3
import Foundation
#if swift(>=3.0)
typealias HashTable<ObjectType: AnyObject> = NSHashTable<ObjectType>
#else
struct HashTable<ObjectType: AnyObject> {
private let _table = NSHashTable.weakObjectsHashTable()
static func weakObjects() -> HashTable<ObjectType> {
// MARK: RawRepresentable Equality
func ==<T: Equatable, U: protocol<RawRepresentable, Equatable> where U.RawValue == T>(left: T?, right: U?) -> Bool {
return left == right?.rawValue
}
func !=<T: Equatable, U: protocol<RawRepresentable, Equatable> where U.RawValue == T>(left: T?, right: U?) -> Bool {
return left != right?.rawValue
}
@robnadin
robnadin / SpacerView+LayoutGuide.swift
Last active February 21, 2020 11:13
Add support for custom layout guide instances in interface builder by using custom UIView subclass. Uses method swizzling to swap out the view during nib decoding.
private extension UIView {
private struct Static {
static let initialize: (AnyClass) -> Void = { (aClass: AnyClass!) in
let swizzle: (Selector, Selector) -> Void = { (original, swizzled) in
let originalSelector = original
let swizzledSelector = swizzled
let originalMethod = class_getInstanceMethod(aClass, originalSelector)
let swizzledMethod = class_getInstanceMethod(aClass, swizzledSelector)