
import Foundation
import UIKit
extension Data {
    public var bytes: [UInt8] {
        return [UInt8](self)
    }
    
    func hexEncodedString() -> String {
        return map { String(format: "%02hhx", $0) }.joined()
    }
    
    func makeDigitalString() -> String {
        //todo: check numeric
        var s: String = ""
        for i in 0...bytes.count-1 {
            if (bytes[i] >= 0 &&  bytes[i] <= 9) {
                s += String(bytes[i])
            }
        }
        return s
    }
}

@available(iOS 14.0, *)
extension UISwitch {
    
    func setOnValueChangeListener(onValueChanged :@escaping () -> Void){
        self.addAction(UIAction(){ action in
            
            onValueChanged()

        }, for: .valueChanged)
    }
}
