Skip to content

Instantly share code, notes, and snippets.

View wotjd's full-sized avatar

wotjd wotjd

  • Seoul, South Korea
View GitHub Profile
@wotjd
wotjd / roundable_button.swift
Created November 26, 2019 06:52
roundable button
import UIKit
class CustomRoundableButton: UIButton {
@IBInspectable var rounded: Bool = false {
didSet { self.updateCornerRadius() }
}
var cornerRadius: CGFloat?
override func layoutSubviews() {
super.layoutSubviews()
import UIKit
extension UIView {
class func computeDampingRatio(tension: CGFloat, friction: CGFloat, mass: CGFloat) -> CGFloat {
friction / (2 * sqrt(mass * tension))
}
class func animate(
withTension tension: CGFloat,
friction: CGFloat,
@wotjd
wotjd / convert_strings.swift
Created November 27, 2019 07:21
convert raw id, string file to strings file
/*
id.txt example:
stringid1
stringid2
...
eng.txt example:
hello
@wotjd
wotjd / custom_flat_swift4.stencil
Created November 27, 2019 11:33
a customized swiftgen template
// swiftlint:disable all
// Generated using SwiftGen, by O.Halligon — https://github.com/SwiftGen/SwiftGen
{% if tables.count > 0 %}
{% set accessModifier %}{% if param.publicAccess %}public {% endif %}{% endset %}
import Foundation
// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length
extension Dictionary {
func cloneWith(_ dict: [Key: Value]) -> [Key: Value] {
var result = self
dict.forEach { key, value in result[key] = value }
return result
}
}
// usage
let dict: [Int: Any] = [1: "abc", 2: "cde"]
class RespondingButton: UIButton, UIKeyInput {
override var canBecomeFirstResponder: Bool { return true }
var hasText: Bool = true
var autocorrectionType: UITextAutocorrectionType = .no
func insertText(_ text: String) {}
func deleteBackward() {}
}
@wotjd
wotjd / Dark-Readability.xccolortheme
Last active January 20, 2020 10:57
xcode theme; Dark and Easy to read; similar to default dark theme
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>DVTConsoleDebuggerInputTextColor</key>
<string>0.706581 0.741758 0.725335 1</string>
<key>DVTConsoleDebuggerInputTextFont</key>
<string>SFMono-Bold - 13.0</string>
<key>DVTConsoleDebuggerOutputTextColor</key>
<string>0.706581 0.741758 0.725335 1</string>
@wotjd
wotjd / Arithmeticable.swift
Created January 21, 2020 09:08
enables arithmetic operation even optional
protocol Arithmeticable {
static func +(lhs: Self, rhs: Self) -> Self
static func -(lhs: Self, rhs: Self) -> Self
static func *(lhs: Self, rhs: Self) -> Self
static func /(lhs: Self, rhs: Self) -> Self
static func <(lhs: Self, rhs: Self) -> Bool
static func <=(lhs: Self, rhs: Self) -> Bool
static func >(lhs: Self, rhs: Self) -> Bool
static func >=(lhs: Self, rhs: Self) -> Bool
@wotjd
wotjd / optionals_to_tuple.swift
Created February 3, 2020 02:14
Bind Multiple Optionals to Tuple
import UIKit
enum OptionalError: Error {
case noValue
}
extension Optional {
// https://www.swiftbysundell.com/tips/unwrapping-an-optional-or-throwing-an-error/
func orThrow(_ errorExpression: @autoclosure () -> Error = OptionalError.noValue) throws -> Wrapped {
guard let value = self else { throw errorExpression() }
class ParentViewController: UIViewController {
let button: UIButton()
...
func onTapButton() {
let popupVC = PopupViewController()
popupVC.onDoneBlock = { [weak self] in
self?.moveToNextView()
}
}