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 ...
随机推荐
- 十六、JSONObject与JSONArray使用-不刷新页面做回写显示
需要导入:json-lib-2.2.2-.jar包 1.json:就是一个键对应一个值,超级简单的一对一关系.对于json嵌套,只要记住符号“:”前是键,符号后是值大括号成对找. String arr ...
- [Tommas] ERP系统测试用例设计1(转)
问题: 1.如何进行ERP系统测试用例设计? 2.ERP系统测试用例设计过程? 3.ERP系统测试用例设计的方法? ERP系统本身是一种业务流程很复杂,单据报表众多,逻辑性很强的系统,质量保证方面很难 ...
- SystemVerilog Assertion 设计、调试、测试总结(3)
上两篇主要是讲述断言的概念,基本语法,总结等等 这一篇主要是以PPT的形式展示各个场景下关于断言的应用. 为了在设计中加入断言的功能,因此需要写一个DUT.如下: `define `define fr ...
- Metasploit学习笔记——社会工程学
1.社会工程学攻击案例——伪装木马 Linux命令终端输入命令msfvenom -l payloads用来列出攻击载荷,grep命令用来查询所需要的攻击载荷,条件是windows系统.要有回连至监听主 ...
- [LuoguP1203][USACO1.1]P1203 Broken Necklace
Solution 这道题数据规模奇小,因此大部分人都使用了暴力搜索的方法,这也是我一开始的想法. 对于 100100%100 的数据,3≤n≤3503≤n≤3503≤n≤350 的确可以如此,但暴力搜 ...
- golang的传值调用和传引用调用
传值还是传引用 调用函数时, 传入的参数的 传值 还是 传引用, 几乎是每种编程语言都会关注的问题. 最近在使用 golang 的时候, 由于 传值 和 传引用 的方式没有弄清楚, 导致了 BUG. ...
- Redis集合类型
集合是元素无序且唯一的列表 命令 增加元素 SADD key member [member ...] > SADD letters a (integer) 1 > SADD letters ...
- django的save方法被调用时数据是如何被保存的
发送一个django.db.models.signals.pre_save信号,以允许监听该信号的函数完成一些自定义操作. 预处理数据.如果需要,对对象的每个字断进行自动转换. 准备数据库数据.要求咩 ...
- 1-8SpringBoot之切面AOP
SpringBoot提供了强大AOP支持,我们前面讲解过AOP面向切面,所以这里具体AOP原理就补具体介绍: AOP切面主要是切方法,我们一般搞一些日志分析和事务操作,要用到切面,类似拦截器: @As ...
- Codeforces Round #624 (Div. 3)(题解)
Codeforces Round #624 (Div.3) 题目地址:https://codeforces.ml/contest/1311 B题:WeirdSort 题意:给出含有n个元素的数组a,和 ...