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 / 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)
}
}
@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
import Foundation
protocol Engine {
func startEngine()
func stopEngine()
}
class TrainEngine : Engine {
func startEngine() {
print("Engine started")
let intArray = [1,2,3,4,5]
// using for loop
var forResult = [Int]()
for num in intArray {
forResult.append(num + 1)
}
print(forResult) // [2,3,4,5,6]
let intArray = [[1,2],[3,4],[5]]
var flatMapResult = intArray.flatMap { $0 }
print(flatMapResult) // [1,2,3,4,5]