This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public struct MixinWrapper<Base> { | |
public var base: Base | |
init(_ base: Base) { | |
self.base = base | |
} | |
} | |
public protocol MixinWrapperCompatible { | |
associatedtype MixinWrapperBase |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import LocalAuthentication | |
class BiometricsUtils { | |
//Should not be singleton as always success after first time checked | |
//static let shared: BiometricsUtils = .init() | |
private lazy var context = LAContext() | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftyJSON | |
public protocol JSONDecodable { | |
static func decode(from json: JSON) throws -> Self | |
} | |
extension JSON: JSONDecodable { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enum RegularType { | |
case scientificNotation | |
case shitcoinPrice | |
case url | |
case evmAddress | |
case btcAddress | |
case solanaAddress | |
case zeroAmount | |
case string(String) | |
case validAmountInput(_ decimals: Int) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { | |
if string.count > 0 { | |
if string.count == 1, textField.text.isNilOrEmpty { | |
if let single = string[0], (single == "." || single == "0") {// auto set . or 0 to 0. | |
textField.text = "0." | |
let newPosition = textField.endOfDocument | |
textField.selectedTextRange = textField.textRange(from: newPosition, to: newPosition) | |
textField.sendActions(for: .valueChanged) | |
return false | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import BigInt | |
extension BigUInt { | |
func string(decimals: Int) -> String { | |
"\(self)".bigIntToString(decimals: decimals) | |
} | |
} | |
extension BigInt { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func fetchFromRemote(by ids: [MKAssetId]) { | |
let group = DispatchGroup() | |
let queue = DispatchQueue(label: "felix.hu.remote.assets") | |
let semaphore = DispatchSemaphore(value: 1) | |
for id in ids { | |
queue.async { // queue.async still sync but new thread, if queue.sync is main thread will cause dead lock | |
group.enter() | |
semaphore.wait() | |
Task { | |
do { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array { | |
func convertTo2DArray(rawCount: Int) -> [[Element]] { | |
let array = stride(from: 0, to: self.count, by: rawCount).map { (index) -> [Element] in | |
if (index + rawCount) > self.count { | |
return Array(self[index...]) | |
} else { | |
return Array(self[index..<index + rawCount]) | |
} | |
} |