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: "")+"\n\n"+NSLocalizedString("最小转帐量", comment: "")+"\n\n"+NSLocalizedString("手续费", comment: "")+"\n\n"+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())"+"\n\n", 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: "")+"\n\n", 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: "")+"\n\n", 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()

}

swift中数据之间的转换的更多相关文章

  1. C#字符串和数据之间的转换

    c#中不仅仅存在数值类型的数据之间的转换,字符串和数值之间也是可以互相转换的,只是方法不同而已. 1 数值型转换为字符型 数值型数据转换为字符串用ToString()方法即可实现 int num1=1 ...

  2. Swift数字类型之间的转换

    Swift数字类型之间的转换Swift是一种安全的语言,对于类型的检查非常严格,不同类型之间不能随便转换.一.整型之间的转换在C和Objective-C等其他语言中,整型之间有两种转换方法:从小范围数 ...

  3. ArcGIS中数据之间的转换接口IFeatureDataConverter2

    之前我写过一篇文章关于ArcGIS各种空间数据格式之间转换的通用方法:ArcGIS中sde,mdb,shp数据之间的转换.这里使用的主要接口方法就是用到了IFeatureDataConverter接口 ...

  4. swift 中数据类型那个的转换

    在swift中关于数据类型的转换,如果参数是可选类型? 那么打印或者转换的结果 会带有Optional 字样,,

  5. JavaBean和json数据之间的转换(一)简单的JavaBean转换

    1.为什么要使用json? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,因为其高性能.可读性强的原因,成为了现阶段web开发中前后端交互数据的主要数据 ...

  6. JavaBean和json数据之间的转换(二)含有date类型的JavaBean

    1.前言 上次讲了简单的JavaBean和json格式之间的转换,代码很简单,但是实际过程中,往往用到的JavaBean都是比较复杂的,其他的字段还好,如果JavaBean中包含了date类型的字段, ...

  7. python数据之间的转换和关系

    首先数据类型在我看来分为两类: 容器类:能存储数据,例如:元祖.列表.集合.字符串. 原子类:单纯保存数值,例如:整数.浮点数.复数. 容器类与容器类之间,一般都可以进行两两之间的转化. 原子类与原子 ...

  8. unicode下char*和CString和一些数据之间的转换

    首先mfc下字符串只有两种数据:char(一个字节)和wchar_t(两个字节),很多其他数据类型如TCHAR,WCHAR等都是这个两个基本类型的宏定义,BYTE是uchar 1.对话框打印char* ...

  9. java 中数据的强制转换 和计算的补码运算

    原码 反码 补码的定义与运算 1原码: 原码是将十进制或者其他进制的数转换为二进制表示(且要根据数据的类型转换) 如:130 (默认是Int类型,则是4个字节) 原码是:00000000 000000 ...

随机推荐

  1. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 辅助类:"text-danger" 类的文本样式

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  2. Python作业篇 day03

    ###一.有变量name = 'aleX leNb',完成如下的操作 name = 'aleX leNb' name1 = ' aleX leNb ' #1.移除name1 变量对应的值两边的空格 , ...

  3. java Vector的特点与使用

    Vector Vector的数据结构 基于数组,大小可变(数组扩容). Vector与ArrayList的比较 我看了下源码,最大区别就是Vector的方法加了synchronized,是线程安全的 ...

  4. js实现深度拷贝

    js实现拷贝,使用普通赋值对象,在操作其中一个对象值的时候,另一个也会更改,不符合需求 因此引入深度拷贝,以下为实现深度拷贝的几种法: Object.assign // 合并多个对象 var targ ...

  5. VUE 使用axios请求第三方接口数据跨域问题解决

    VUE是基于node.js,所以解决跨域问题,设置一下反向代理即可. 我这里要调用的第三方接口地址为 http://v.juhe.cn/toutiao/index?type=top&key=1 ...

  6. 【转】stm32 IAP升级程序

      一.什么是IAP,为什么要IAP       IAP即为In Application Programming(在应用中编程),一般情况下,以STM32F10x系列芯片为主控制器的设备在出厂时就已经 ...

  7. CSP-S2019 爆炸记

    DAY -1 停课的第五天.早上来机房教练居然不在,先看了一道憨题,发现ST表+二分查找nlogn水过,然后发现单调栈可以O(n),肥肠开心 打了走人. 然后就开始颓了(逃 颓了一会之后看愤怒的小鸟这 ...

  8. Day9 - J - 吉哥系列故事——恨7不成妻 HDU - 4507

    单身! 依然单身! 吉哥依然单身! DS级码农吉哥依然单身! 所以,他生平最恨情人节,不管是214还是77,他都讨厌! 吉哥观察了214和77这两个数,发现: 2+1+4=7 7+7=7*2 77=7 ...

  9. SpringMVC 转发、重定向

    转发.重定向到其它业务方法 @org.springframework.stereotype.Controller @RequestMapping("/userController" ...

  10. i春秋-密码-IceCTF-Alien Message

    题目: 对应的解题图片: 解的时候,符号大点的是大写,小点的是小写. IceCTF{gOOd_n3wZ_3vERyoN3_1_L1k3_fU7ur4Ma_4nd_tH3iR_4maZ1nG_3As7e ...