Skip to content

Instantly share code, notes, and snippets.

View codelynx's full-sized avatar

Kaz Yoshikawa codelynx

View GitHub Profile
@codelynx
codelynx / UIKit+swizzling.swift
Created March 17, 2021 09:10
Example of swizzling UIKit classes
//
// UIKit+swizzling.swift
//
// The MIT License (MIT)
//
// Copyright (c) 2022 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 / Thread+Z.swift
Created March 15, 2021 12:26
Regardless of thread, execute closure on main thread
//
// Thread+Z.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2020 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 / XResponder+Z.swift
Created March 13, 2021 14:25
make UIResponder/NSResponder conforms to Sequence protocol
//
// UIResponder+Z.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2021 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 / UIGestureRecognizer+Z.swift
Created March 12, 2021 01:53
UIGestureRecognizer extension to keep arbitrary values associated with any gesture recognizers
//
// UIGestureRecognizer+Z.swift
// ZKit
//
// The MIT License (MIT)
//
// Copyright (c) 2021 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 / NSObject+class_copyPropertyList.swift
Last active March 21, 2024 08:22
Use class_copyPropertyList to extract properties from NSObject based object,
// source:
// https://stackoverflow.com/questions/24750186/i-cant-get-properties-of-a-class-using-swift-by-class-copypropertylist
import Foundation
extension NSObject {
func dictionaryRepresentation() -> [String: Any] {
@codelynx
codelynx / String+makeuniquename.swift
Created March 3, 2021 02:59
Generating a unique name by adding or incrementing suffix number of base name.
// String.makeUniqueName
//
// The MIT License (MIT)
//
// Copyright (c) 2021 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
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
@codelynx
codelynx / String+incrementingTrailingNumber.swift
Created February 25, 2021 23:41
string by incremented trailing number good for a suggestion of duplicated file name
// String+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 / delegate_chaining_workaround.swift
Last active October 30, 2020 04:35
Swift Playground: This code demonstrate deepest view controller to a certain view controller conforms to a certain protocol by taking advantage of responder chain.
// The MIT License (MIT)
//
// Copyright (c) 2020 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
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
@codelynx
codelynx / UnsafePointer Converter.swift
Created September 13, 2020 14:57
[swift] Unsafe Pointer conversion
//
// Swift UnsafePointer converter
// Kaz Yoshikawa
//
// These code demonstrates how to convert swift pointers to the other forms of pointers.
//
// Source:
// Swift の Array やら ArraySlice やらポインタの変換まとめ
// https://qiita.com/Satachito/items/4c39c9b06304e4d86660
//
@codelynx
codelynx / UnitLength+points.swift
Created May 12, 2020 02:42
extension of UnitLength (Measurement) to support Points
import Foundation
extension UnitLength {
static let points = UnitLength(symbol: "pt", converter: UnitConverterLinear(coefficient: 0.0003527778, constant: 0))
}
let inches = Measurement(value: 1, unit: UnitLength.inches) // 1.0 in
let points = inches.converted(to: UnitLength.points) // 71.99999546456722 pt