Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@codelynx
codelynx / gist:cc24d1fead1d9ce779a1
Created March 6, 2015 17:26
Testing Equatable function between base class and its subclass but != seems not working as expected?
// Creature
class Creature : Equatable {
}
func ==(lhs: Creature, rhs: Creature) -> Bool {
return lhs === rhs
}
// Monster
@codelynx
codelynx / Vector3D+Vector2D.swift
Last active November 7, 2015 14:35
Swift 2.0: Vector3D Vector2D
//
// Geometry.swift
// ZKit
//
// Created by Kaz Yoshikawa on 11/6/15.
//
//
import Foundation
import CoreGraphics
@codelynx
codelynx / ZGeoUtils.swift
Created December 4, 2015 00:11
swift: Geometric Utility
//
// ZGeoUtils.swift
// ZKit
//
// Created by Kaz Yoshikawa on 2015/02/08.
// Copyright (c) 2015 Electricwoods LLC. All rights reserved.
//
import Foundation
import CoreGraphics
@codelynx
codelynx / String+Z.swift
Last active December 5, 2015 23:36
common file/path related method
//
// String+Z.swift
// ZKit
//
// Created by Kaz Yoshikawa on 11/10/15.
//
//
import Foundation
@codelynx
codelynx / NSScanner+Z.swift
Created December 11, 2015 00:35
NSScanner Utility
import Foundation
extension NSScanner {
func scanStringFromSet(strings: Set<String>) -> String? {
for string in strings {
if self.scanString(string, intoString: nil) {
return string
}
}
@codelynx
codelynx / .swift
Created January 14, 2016 18:43
switch statement example
for thing in things {
switch thing {
case 0 as Int:
print("zero as an Int")
case 0 as Double:
print("zero as a Double")
case let someInt as Int:
print("an integer value of \(someInt)")
case let someDouble as Double where someDouble > 0:
print("a positive double value of \(someDouble)")
@codelynx
codelynx / ZSearchField.swift
Created March 23, 2016 19:44
ZSearchField is able to detect when focused or unfocused to its delegate. If you are using Interface Builder make sure to change the NSSerachField class to ZSearchField, and t's delegate must conforms to ZSearchFieldDelegate not NSTextFieldDelegate.
protocol ZSearchFieldDelegate: NSTextFieldDelegate {
func searchFieldDidBecomeFirstResponder(textField: ZSearchField)
func searchFieldDidResignFirstResponder(textField: ZSearchField)
}
class ZSearchField: NSSearchField, NSTextDelegate {
var expectingCurrentEditor: Bool = false
@codelynx
codelynx / String+Color.swift
Last active March 24, 2016 07:09
convert from hexadecimal string to UIColor
//
// String+Color.swift
// ZKit
//
// Created by Kaz Yoshikawa on 3/24/16.
// Copyright © 2016 Electricwoods LLC Inc. The MIT License.
//
import Foundation
import UIKit
@codelynx
codelynx / Array+addition.swift
Last active March 24, 2016 13:14
Extension for Array to remove an object from it.
extension Array where Element: Equatable {
mutating func remove<Element: Equatable>(object: Element) -> Array {
self = self.filter { $0 as? Element != object }
return self
}
}
@codelynx
codelynx / ZMapTable.swift
Created March 26, 2016 07:12
NSMapTable wrapper
//
// ZMapTable.swift
// ZKit
//
// Created by Kaz Yoshikawa on 3/26/16.
// Copyright © 2016 Electricwoods LLC. All rights reserved.
//
import Foundation