• swift的异常处理:本质是错误信息的传递方式


        func response(from resultObject: Any) throws -> Response {

            guard

                let dict = resultObject as? [String: AnyObject],

                let transaction = PendingTransaction.from(dict)

            else {

                throw CastError(actualValue: resultObject, expectedType: Response.self)

            }

            return transaction

        }

       

     func convertPrivateKeyToKeystoreFile(privateKey: String, passphrase: String) -> Result<[String: Any], KeystoreError> {

            guard let data = Data(hexString: privateKey) else {

                return .failure(KeystoreError.failedToImportPrivateKey)

            }

            do {

                let key = try KeystoreKey(password: passphrase, key: data)

                let data = try JSONEncoder().encode(key)

                let dict = try JSONSerialization.jsonObject(with: data, options: []) as! [String: Any]

                return .success(dict)

            } catch {

                return .failure(KeystoreError.failedToImportPrivateKey)

            }

        }

        var asDictionary: [String: Any]? {

            if let data = self.data(using: .utf8) {

                do {

                    return try JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]

                } catch {

                    print(error.localizedDescription)

                    return [:]

                }

            }

            return [:]

        }

  • 相关阅读:
    日期转换DateTime
    linux 常用命令
    springcloud集成 xxl-job
    maven-阿里云镜像
    mysql 8.0+忘记root密码-linux
    java注解与自定义注解
    mysql联合索引的生效规则
    Maven常用命令及其作用、常见问题、常用命令使用场景举例
    反射的理解
    VirtualBox创建centos
  • 原文地址:https://www.cnblogs.com/feng9exe/p/10430086.html
Copyright © 2020-2023  润新知