Skip to content

Instantly share code, notes, and snippets.

@vhart
vhart / ProtocolGenericsPt2.swift
Last active November 28, 2016 17:16
ProtocolGenericPt2
struct Car: Drivable {
let numberOfWheels = 4
func drive() { }
}
struct Motorcycle: Drivable {
let numberOfWheels = 2
let licensePlate = "asdf123"
@vhart
vhart / ProtocolGenericsPt1.swift
Last active November 28, 2016 17:16
Protocol-Generics Pt 1
protocol Drivable {
func drive()
var numberOfWheels: Int { get }
}
func startTraveling(with transportation: Drivable) { }
func startTraveling<D: Drivable>(with transportation: D) { }
@vhart
vhart / UIColorFromHex.swift
Last active January 6, 2017 03:00
UIColor from hex
extension UIColor {
convenience init? (fromHex hex: String) {
let hexPattern = try! NSRegularExpression(pattern: "^[0-9a-fA-F]{6}$",
options: [.anchorsMatchLines])
let range = NSRange(location: 0, length: hex.characters.count)
guard hexPattern.matches(in: hex,
options: [],
range: range).count == 1
else { return nil }
//
// main.m
// variable2
//
// Created by Varindra Hart on 6/4/15.
// Copyright (c) 2015 Varindra Hart. All rights reserved.
//
#import <Foundation/Foundation.h>
@vhart
vhart / gist:1a3ad4942f495854f33b
Last active August 29, 2015 14:22
12 Days of Christmas
//
// main.m
// 12DaysOfChristmas
//
// Created by Varindra Hart on 6/4/15.
// Copyright (c) 2015 Varindra Hart. All rights reserved.
//
#import <Foundation/Foundation.h>