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 / dispatch_queue_test.swift
Created September 21, 2018 10:17
test dispatch queue, dispatch semaphore, ...
import UIKit
import Foundation
let queue = DispatchQueue(label: "wotjd", attributes: .concurrent)
func sendMessage(str: String, pendingTime: UInt32, completion: @escaping () -> Void) {
queue.async {
sleep(pendingTime)
print(str)
completion()
@wotjd
wotjd / StackViewController.swift
Created November 6, 2018 15:47
StackView에 동적으로 버튼 추가
//
// StackViewController.swift
// TableViewTest
//
// Created by edge on 06/11/2018.
// Copyright © 2018 castis. All rights reserved.
//
import UIKit
import UIKit
class HighlightButton: UIButton {
@IBInspectable var highlightTintColor : UIColor?
private var prevTintColor : UIColor?
override var isHighlighted : Bool {
didSet {
if self.isHighlighted != oldValue {
self.prevTintColor = self.tintColor
@wotjd
wotjd / ToggleButton.swift
Created November 27, 2018 05:49
A Simple ToggleButton with Color (subclassed UIButton)
import UIKit
class ToggleButton: UIButton {
@IBInspectable var toggledTintColor : UIColor?
private var prevTintColor : UIColor?
var isOn : Bool = false
convenience init() {
@wotjd
wotjd / CompareVersion.swift
Created December 17, 2018 07:36
Compare Version
extension String {
func isNewer(than compareVersion: String) -> Bool {
if self.compare(compareVersion, options: NSString.CompareOptions.numeric) == ComparisonResult.orderedDescending {
return true
}
return false
}
}
@wotjd
wotjd / RepeatingTimer.swift
Last active April 3, 2020 14:47 — forked from danielgalasko/RepeatingTimer.swift
A repeating GCD timer that can run on a background queue
import Foundation
/// RepeatingTimer mimics the API of DispatchSourceTimer but in a way that prevents
/// crashes that occur from calling resume multiple times on a timer that is
/// already resumed (noted by https://github.com/SiftScience/sift-ios/issues/52
class RepeatingTimer {
// MARK: State
private enum State {
case suspended
case resumed
@wotjd
wotjd / LocalNotification.swift
Created January 9, 2019 11:26
request local notification with specified scheduled time (date / interval)
import UserNotification
struct LocalNotification {
static func isDuplicatedNotification(identifier: String, completion: @escaping (Bool) -> () = {_ in}) {
UNUserNotificationCenter.current().getPendingNotificationRequests { notifications in
let dumNotis = notifications.filter { $0.identifier == identifier }
completion(!dumNotis.isEmpty)
}
}
import Foundation
protocol Engine {
func startEngine()
func stopEngine()
}
class TrainEngine : Engine {
func startEngine() {
print("Engine started")
@wotjd
wotjd / scoping.swift
Created May 23, 2019 04:42
swift block scope idea for test (protocol not allowed)
import Foundation
public func FuntionScope(_ closure: () -> () ) {
closure()
}
public let TupleScope = { (c: () -> ()) in c() }
public let TupleExpScope: (() -> ()) -> () = { $0() }
// adding closure typealias
@wotjd
wotjd / ReplaceString.swift
Created July 22, 2019 03:08
특정 문자열 치환
import Foundation
let uuid = NSUUID().uuidString //"3B156152-8CD1-4845-A85C-1722AACC2453"
uuid.replacingOccurrences(of: "-", with: "") //"3B1561528CD14845A85C1722AACC2453"