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: "")+"\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中数据之间的转换的更多相关文章
- C#字符串和数据之间的转换
c#中不仅仅存在数值类型的数据之间的转换,字符串和数值之间也是可以互相转换的,只是方法不同而已. 1 数值型转换为字符型 数值型数据转换为字符串用ToString()方法即可实现 int num1=1 ...
- Swift数字类型之间的转换
Swift数字类型之间的转换Swift是一种安全的语言,对于类型的检查非常严格,不同类型之间不能随便转换.一.整型之间的转换在C和Objective-C等其他语言中,整型之间有两种转换方法:从小范围数 ...
- ArcGIS中数据之间的转换接口IFeatureDataConverter2
之前我写过一篇文章关于ArcGIS各种空间数据格式之间转换的通用方法:ArcGIS中sde,mdb,shp数据之间的转换.这里使用的主要接口方法就是用到了IFeatureDataConverter接口 ...
- swift 中数据类型那个的转换
在swift中关于数据类型的转换,如果参数是可选类型? 那么打印或者转换的结果 会带有Optional 字样,,
- JavaBean和json数据之间的转换(一)简单的JavaBean转换
1.为什么要使用json? JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,因为其高性能.可读性强的原因,成为了现阶段web开发中前后端交互数据的主要数据 ...
- JavaBean和json数据之间的转换(二)含有date类型的JavaBean
1.前言 上次讲了简单的JavaBean和json格式之间的转换,代码很简单,但是实际过程中,往往用到的JavaBean都是比较复杂的,其他的字段还好,如果JavaBean中包含了date类型的字段, ...
- python数据之间的转换和关系
首先数据类型在我看来分为两类: 容器类:能存储数据,例如:元祖.列表.集合.字符串. 原子类:单纯保存数值,例如:整数.浮点数.复数. 容器类与容器类之间,一般都可以进行两两之间的转化. 原子类与原子 ...
- unicode下char*和CString和一些数据之间的转换
首先mfc下字符串只有两种数据:char(一个字节)和wchar_t(两个字节),很多其他数据类型如TCHAR,WCHAR等都是这个两个基本类型的宏定义,BYTE是uchar 1.对话框打印char* ...
- java 中数据的强制转换 和计算的补码运算
原码 反码 补码的定义与运算 1原码: 原码是将十进制或者其他进制的数转换为二进制表示(且要根据数据的类型转换) 如:130 (默认是Int类型,则是4个字节) 原码是:00000000 000000 ...
随机推荐
- nmap 速查命令
进行ping扫描,打印出对扫描做出响应的主机,不做进一步测试(如端口扫描或者操作系统探测) nmap -sP 192.168.1.0/24 仅列出指定网络上的每台主机,不发送任何报文到目标主机 nam ...
- UISearchBar设置背景色
1.关于UISearchBar的背景颜色,竟然要如下设置才正常: [documentSearchView setBackgroundImage:[UIImage new]]; documentSear ...
- OPCDA通信--工作在透明模式下的CISCO ASA 5506-X防火墙配置
尊重原创,转发请声名 inside OPCSERVER 一台 outside OPCCLIENT 一台 route模式 配置没成功,放弃,采用透明模式 !----进入全局配置-- configure ...
- hdu 2838 Cow Sorting 树状数组求所有比x小的数的个数
Cow Sorting Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- Pytorch【直播】2019 年县域农业大脑AI挑战赛---初级准备(一)切图
比赛地址:https://tianchi.aliyun.com/competition/entrance/231717/introduction 这次比赛给的图非常大5万x5万,在训练之前必须要进行数 ...
- Censoring「USACO 2015 Feb」
题目描述 有一个S串和一个T串,长度均小于1,000,000,设当前串为U串,然后从前往后枚举S串一个字符一个字符往U串里添加,若U串后缀为T,则去掉这个后缀继续流程. 输入格式 包含两行,第一行为S ...
- 回收 PV【转】
当 PV 不再需要时,可通过删除 PVC 回收. 当 PVC mypvc1 被删除后,我们发现 Kubernetes 启动了一个新 Pod recycler-for-mypv1,这个 Pod 的作用就 ...
- Kubernetes企业安全
导读 所有利益相关者预先参与一个布局良好的计划,这是构建更安全的容器环境的第一步.如今,容器仍然是应用程序部署和迁移的主流技术.行业专家Paul Rubens将其分解为可以理解的几个部分——陷阱.容器 ...
- anaconda 创建虚拟环境(自己版本)
首先安装anaconda(3) Anacond的介绍Anaconda指的是一个开源的Python发行版本,其包含了conda.Python等180多个科学包及其依赖项. 因为包含了大量的科学包,Ana ...
- 我的Grunt之旅-初识gruntfile文件
时间:2018-03-06 18:23 事件:配置 gruntfile.js文件 首先,回忆一下之前的点,grunt项目下面必须有两个文件 ,第一个 package.json ,第二个 Gru ...