zoukankan      html  css  js  c++  java
  • swift中数据之间的转换

    1.swift 开发 - NSDictionary与NSData互转、Dictionary与Data互转

    https://blog.csdn.net/SuperMageHuang/article/details/54963236

    1、NSDictionary转NSData
    let data:NSData =NSKeyedArchiver.archivedData(withRootObject:dataDic) asNSData

    2、NSData转NSDictionary
    let dic =NSKeyedUnarchiver.unarchiveObject(with: dataas! Data)as! NSDictionary


    3、NSDictionary转Data
    let date =try! JSONSerialization.data(withJSONObject: dic, options: .prettyPrinted)

    4、Data转Dictionary
    let json =try! JSONSerialization.jsonObject(with: data, options: .mutableContainers)as! Dictionary<String,String>

    2.(UITextField.text as NSSTring).floatValue

    使用一个label 显示多行

    private func setData(showStr: String) {

            DispatchQueue.main.async {

                self.leftTipLabel!.text = NSLocalizedString("可用", comment: "")+" "+NSLocalizedString("最小转帐量", comment: "")+" "+NSLocalizedString("手续费", comment: "")+" "+NSLocalizedString("到账数量", comment: "")

            }

            self.leftTipLabel?.numberOfLines = 0

            let attributedStrM : NSMutableAttributedString = NSMutableAttributedString()

            attributedStrM.append(NSAttributedString(string: available, attributes: [NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: "#F1B11B")]))

            attributedStrM.append(NSAttributedString(string: " (dataDict["currency"].stringValue.uppercased())"+" ", attributes: [NSAttributedString.Key.foregroundColor: ThemeColor.sharedInstance.getTextColor()]))

            attributedStrM.append(NSAttributedString(string: String(format: "%.3f", ((self.minWithdrawQuantity as String) as NSString).doubleValue), attributes: [NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: "#F1B11B")]))

            attributedStrM.append(NSAttributedString(string: NSLocalizedString("个",  comment: "")+" ", attributes: [NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

            var all:Double = 0

            var totalFees:Double = 0

            if self.moneyTextField?.text?.count == 0 {

                all = 0

                totalFees = 0

            }else if (self.moneyTextField!.text! as NSString).doubleValue < (self.minWithdrawQuantity as NSString).doubleValue{

                all = 0

                totalFees = 0

            }else{

                

                let inputf:Double = Double((showStr as NSString).doubleValue)

                let feesp:Double = Double((self.feeS as NSString).doubleValue) * inputf

                if feesp > Double((self.firstFee as NSString).doubleValue) {

                    totalFees = Double((self.firstFee as NSString).doubleValue)

                    all = (showStr as NSString).doubleValue - totalFees

                    

                }else{

                    totalFees = feesp

                    all = Double((showStr as NSString).doubleValue) - totalFees

                    

                }

            }

            //手续费  "(totalFees)"

            attributedStrM.append(NSAttributedString(string: String(format: "%.3f", totalFees), attributes: [NSAttributedString.Key.foregroundColor: UIColor.hexadecimalColor(hexadecimal: "#F1B11B")]))

            attributedStrM.append(NSAttributedString(string: NSLocalizedString("个",  comment: "")+" ", attributes: [NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

            

            //到账数量  //"(all - totalFees)"

            attributedStrM.append(NSAttributedString(string: String(format: "%.3f", all), attributes: [NSAttributedString.Key.foregroundColor: QBColor_Orange]))

            attributedStrM.append(NSAttributedString(string: " (self.currentCurrency!)", attributes: [NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

            

            

            self.rightTipLabel?.textAlignment = NSTextAlignment.right

            self.rightTipLabel!.attributedText = attributedStrM

            self.rightTipLabel?.numberOfLines = 0

            

            

            DispatchQueue.main.async {

                self.bottomTipLabel!.text = NSLocalizedString("手续费率", comment: "") + "(self.feeS)" + ", " + NSLocalizedString("单笔不超过", comment: "") + "(self.firstFee)" + "(self.currentCurrency!)" + NSLocalizedString("多少手续费", comment: "")

            }

            

            self.view.layoutIfNeeded()

        }

  • 相关阅读:
    debian系统完全卸载mysql
    已解决:Linux虚拟机创建后无法切换到root
    已解决:win10 下MarkdownPad2渲染出错:This View has crashed!
    计算机网络---运输层
    计算机网络---网络层
    计算机网络---数据链路层
    计算机网络---概述
    计算机网络---物理层
    go的命令行参数---flag
    Go---第九章:使用共享变量实现并发(小知识点笔记)
  • 原文地址:https://www.cnblogs.com/sundaysme/p/11600689.html
Copyright © 2011-2022 走看看