Skip to content

Instantly share code, notes, and snippets.

Avatar

Kendall Helmstetter Gelner KiGi

View GitHub Profile
View CustomHashable.swift
public struct CustomHashable<T>: Hashable {
public let value: T
public typealias HashCalculator = (CustomHashable<T>, inout Hasher) -> Void
public typealias EqualityCalculator = (CustomHashable<T>, CustomHashable<T>) -> Bool
public typealias CacheTransformedData = (T) -> Any?
private let hashCalculator: HashCalculator
private let equalityCalculator: EqualityCalculator
@KiGi
KiGi / gist:c6ddba8ed2276773c9fa
Created Dec 21, 2015
Draw UIView into image from static class method
View gist:c6ddba8ed2276773c9fa
static func buildImageForSize(size:CGSize) -> UIImage?
{
if size.height == 0 || size.width == 0 {
return .None
}
var sigRect = CGRectZero
sigRect.size = size
// The following does NOT work
@KiGi
KiGi / gist:1be0197d9ef4ddfc9970
Created May 7, 2015
Swift 1.2 fileExistsAtPath
View gist:1be0197d9ef4ddfc9970
func checkIfFileExpired( fileURL : NSURL ) -> Bool {
let fileManager = NSFileManager()
if let fileManager.fileExistsAtPath(fileURL) {
var error : NSError? = nil
if let filePath = fileURL.path,
let fileAttr = fileManager.attributesOfItemAtPath(filePath, error: &error),
let creationDate = fileAttr[NSFileModificationDate] as? NSDate {
return creationDate.isBefore(NSDate.oneDayAgo())
} else {
println("problem examining file attributes for \(fileURL): error was \(error)")
@KiGi
KiGi / KHG Swift FizzBuzz
Created Apr 26, 2015
The ever popular FizzBuzz, here a few passes at it in Swift in a playground with multiple implementations and looping methods (including a generator)
View KHG Swift FizzBuzz
import Foundation
// Make constants so the strings can be easily changed.
let fizz = "Fizz"
let buzz = "Buzz"
// Put this its own function just to make different implementations shorter and clearer.
func fizzbBuzzDeterminer( candidateNum : Int, isFizz: Bool, isBuzz : Bool ) -> String
{
var toPrint :String