Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@codelynx
codelynx / UIView+Find.swift
Created March 30, 2016 16:02
UIView extension to find a specific UIViewController type in responder chain. And UIView extension to find specific UIView subclass in view hierarchy toward superview.
// UIView+Find.swift
//
// Copyright (c) 2016 Kaz Yoshikawa. Released under MIT License.
extension UIView {
func findViewController<T: UIViewController>() -> T? {
var responder = self.nextResponder()
while responder != nil {
if let viewController = responder as? T {
// ZMapTable.swift
//
// Copyright (c) 2016 Kaz Yoshikawa. Released under MIT License.
enum ZMapTableOption {
case StrongToWeak
case WeakToStrong
case WeakToWeak
case StrongToStrong
}
@codelynx
codelynx / ZCollection.swift
Created May 16, 2016 18:33
Class version of: Array, Set, Dictionary
//
// ZCollection.swift
// ZKit
//
// Created by Kaz Yoshikawa on 2015/01/12.
// Copyright (c) 2015 Kaz Yoshikawa. All rights reserved.
//
// This software may be modified and distributed under the terms
// of the MIT license.
//
@codelynx
codelynx / UIDevice+storyboard.swift
Created June 2, 2016 08:13
Utility code to load storyboard using ~iphone or ~ipad depending on user interface idiom, something similar to what xib do.
import UIKit
extension UIDevice {
class func storyboard(name name: String, bundle: NSBundle? = nil) -> UIStoryboard {
let userInterfaceIdiom = UIDevice.currentDevice().userInterfaceIdiom
let modifier: String = {
switch userInterfaceIdiom {
case .Pad: return "~ipad"
@codelynx
codelynx / NSScanner+Z.swift
Last active June 3, 2016 17:03
NSScanner Utilities
//
// NSScanner+Z.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / BinaryStringConvertible.swift
Last active June 16, 2016 16:52
Utility code to convert UInt8, UInt16, UInt32, UInt64 into "0" and "1" based string
//
// BinaryStringConvertible.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / ZDictionary.swift
Created June 17, 2016 07:13
Type constrained class (object) version of Array that can be used as reference
//
// ZDictionary.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@codelynx
codelynx / ZManagedObjectStorage.swift
Last active June 18, 2016 18:39
Utility class to manage single persistent with single managed object context with separate model name.
//
// ZManagedObjectStorage.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2016 Electricwoods LLC, Kaz Yoshikawa.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
func synchronized<Result>(lock: NSLock, block: () throws -> Result) rethrows -> Result {
lock.lock()
defer { lock.unlock() }
return try block()
}
let lock = NSLock()
func doThing() {
@codelynx
codelynx / NSFileHandle+Z.swift
Last active July 6, 2016 18:33
Utility methods Reading and Writing Integer, Float, Double for NSFileHandle
//
// NSFileHandle+Z.swift
// ZKit
//
// Created by Kaz Yoshikawa on 2/18/16.
//
//
import Foundation