Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@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 / ZBitVector.swift
Created June 2, 2016 17:48
CFBitVector Swift wrapper
//
// ZBitVector.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 / NSCFRange+Z.swift
Created June 10, 2016 04:02
NSRange, CFRange Utilities
// NSCFRange+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
// in the Software without restriction, including without limitation the rights
@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 / gist:a652dcb463504bec7e6b55daba72abc5
Created July 30, 2016 04:15
NDL市町村コード情報
{
"01000":["北海道","","","都道府県"],
"01100":["北海道","札幌市","サッポロシ","政令指定都市"],
"01202":["北海道","函館市","ハコダテシ","市"],
"01203":["北海道","小樽市","オタルシ","市"],
"01204":["北海道","旭川市","アサヒカワシ","市"],
"01205":["北海道","室蘭市","ムロランシ","市"],
"01206":["北海道","釧路市","クシロシ","市"],
"01207":["北海道","帯広市","オビヒロシ","市"],
"01208":["北海道","北見市","キタミシ","市"],
@codelynx
codelynx / Float16.swift
Last active October 23, 2024 12:51
Utility type to handle Half Precision Float Type (16 bit float) in swift 3.0
//
// Float16.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