Skip to content

Commit

Permalink
Conform BinanceAuth/KucoinAuth to RawRepresentable
Browse files Browse the repository at this point in the history
 - Allows for using @AppStorage.
  • Loading branch information
backslash-f committed Mar 11, 2024
1 parent 209d153 commit 665e14b
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// BinanceAuth+RawRepresentable.swift
//
//
// Created by Fernando Fernandes on 11.03.24.
//

import Foundation

extension BinanceAuth: RawRepresentable {
public typealias RawValue = String

public init?(rawValue: RawValue) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode(BinanceAuth.self, from: data) else {
return nil
}
self = result
}

public var rawValue: RawValue {
guard let data = try? JSONEncoder().encode(self) else {
return "Failed to encode data"
}
guard let jsonString = String(data: data, encoding: .utf8) else {
return "Faile to convert data to String"
}
return jsonString
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// KucoinAuth+RawRepresentable.swift
//
//
// Created by Fernando Fernandes on 06.03.24.
//

import Foundation

extension KucoinAuth: RawRepresentable {
public typealias RawValue = String

public init?(rawValue: RawValue) {
guard let data = rawValue.data(using: .utf8),
let result = try? JSONDecoder().decode(KucoinAuth.self, from: data) else {
return nil
}
self = result
}

public var rawValue: RawValue {
guard let data = try? JSONEncoder().encode(self) else {
return "Failed to encode data"
}
guard let jsonString = String(data: data, encoding: .utf8) else {
return "Faile to convert data to String"
}
return jsonString
}}

0 comments on commit 665e14b

Please sign in to comment.