Skip to content

Instantly share code, notes, and snippets.

View kyungpyoda's full-sized avatar
🙃
Howdy

kyungpyoda

🙃
Howdy
View GitHub Profile
//연결 재시도? 하면서 오류나는 부분입니다.
/*
* We will first check if we are already connected to our counterpart
* Otherwise, scan for peripherals - specifically for our service's 128bit CBUUID
*/
private func retrievePeripheral() {
print("[hoonki] test=\(TransferService.serviceUUID)")
//cleanup()
let connectedPeripherals: [CBPeripheral] = (centralManager.retrieveConnectedPeripherals(withServices: [TransferService.serviceUUID]))
@kyungpyoda
kyungpyoda / DateFormatter_CheatSheet.md
Created April 21, 2021 07:33
DateFormatter cheat sheet
Wednesday, Sep 12, 2018           --> EEEE, MMM d, yyyy
09/12/2018                        --> MM/dd/yyyy
09-12-2018 14:11                  --> MM-dd-yyyy HH:mm
Sep 12, 2:11 PM                   --> MMM d, h:mm a
September 2018                    --> MMMM yyyy
Sep 12, 2018                      --> MMM d, yyyy
Wed, 12 Sep 2018 14:11:54 +0000   --> E, d MMM yyyy HH:mm:ss Z
2018-09-12T14:11:54+0000          --> yyyy-MM-dd'T'HH:mm:ssZ
12.09.18 --> dd.MM.yy
@kyungpyoda
kyungpyoda / Reactive+longPress.swift
Created April 27, 2021 06:57
RxSwift custom LongPress gesture
import RxSwift
extension Reactive where Base: UIButton {
var longPress: Observable<Int> {
return controlEvent(.touchDown)
.flatMapLatest { _ in
Observable.timer(.milliseconds(500), scheduler: MainScheduler.instance)
.takeUntil(self.controlEvent(.touchUpInside))
}
}
@kyungpyoda
kyungpyoda / OneTimeCodeTextField.swift
Last active May 13, 2021 05:26
인증번호(OneTime Code) 입력 뷰
//
// OneTimeCodeTextField.swift
//
// Created by 홍경표 on 2021/05/13.
//
import UIKit
final class OneTimeCodeTextField: UITextField {
@kyungpyoda
kyungpyoda / String+toMoneyFormat.swift
Last active May 31, 2021 08:05
Money Format with Thousand Separator
extension String {
func toMoneyFormat() -> String {
guard let amount = Int(self) else { return self }
let formatter = NumberFormatter()
formatter.numberStyle = .decimal
return formatter.string(for: amount) ?? self
}
@kyungpyoda
kyungpyoda / Cell+Reusable.swift
Created May 25, 2021 11:59
Reusable Cell Extension
//
// Cell+Reusable.swift
//
// Created by 홍경표 on 2021/04/12.
//
import UIKit
protocol Reusable {
static var reuseIdentifier: String { get }
@kyungpyoda
kyungpyoda / Encodable+dictionary.swift
Created May 27, 2021 04:43
[Swift] Encodable instance to dictionary
extension Encodable {
subscript(key: String) -> Any? {
return dictionary[key]
}
var dictionary: [String: Any] {
let dict: [String: Any]? = try? JSONSerialization.jsonObject(with: JSONEncoder().encode(self)) as? [String: Any]
return dict ?? [:]
}
@kyungpyoda
kyungpyoda / CodableInheritanceExample.swift
Created May 28, 2021 01:17
[Swift] Codable class and inheritance
//
// CodableInheritanceExample.swift
//
// Created by 홍경표 on 2021/05/28.
//
class BaseResponse: Codable {
var retCode: Int = 0
private enum CodingKeys: String, CodingKey {
@kyungpyoda
kyungpyoda / Logger.swift
Created May 28, 2021 05:03
[Swift] iOS custom Logger for debugging
//
// Logger.swift
//
// Created by 홍경표 on 2021/05/28.
//
import Foundation
final class Logger {
@kyungpyoda
kyungpyoda / NSAttributedString+withPrefixImage.swift
Last active June 2, 2021 07:45
[Swift] iOS Implement Prefix Image String by using NSAttributedString
//
// NSAttributedString+withPrefixImage.swift
//
// Created by 홍경표 on 2021/05/31.
//
import UIKit.UIImage
extension NSAttributedString {