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 ...
随机推荐
- DateTime.Now.ToFileTime
var s = System.DateTime.Now.ToFileTime().ToString(); DateTime.Now.ToFileTime() 可以获得当前时间的长整型数字,这个数字应该 ...
- mac允许安装任何来源的软件
如果在“系统偏好设置”--“安全性与隐私”--“通用”版面没有像下面的选项.那么请打开终端,使用命令行操作,之后重新进刚刚的设置界面,会出现“任何来源”的选项. 命令行:(请复制使用) sudo sp ...
- 关于Redis 分布式 微服务 集群Cluster
一:Redis 1,redis是一个高性能的键值对存储方式的数据库,同时还提供list,set,zset,hash等数据结构的存储. 2,Redis运行在内存中但是可以持久化到磁盘,所以在对不同数据集 ...
- bitcoin01
bitcoin, blockchain 本文只是初步表面认识比特币的笔记... 详细信息请看相关链接. 比特币除了耗电,耗硬盘存储空间,还有无法预测,无法控制的风险. 1. Satoshi_Nakam ...
- 修剪草坪 HYSBZ - 2442
在一年前赢得了小镇的最佳草坪比赛后,FJ变得很懒,再也没有修剪过草坪.现在,新一轮的最佳草坪比赛又开始了,FJ希望能够再次夺冠. 然而,FJ的草坪非常脏乱,因此,FJ只能够让他的奶牛来完成这项工作.F ...
- PHP实现微信网页登陆授权开发
这篇文章主要介绍了关于PHP实现微信网页登陆授权开发,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下 更多PHP相关知识请关注我的专栏PHPzhuanlan.zhihu.com 微信开 ...
- android 根据res文件夹下(如res/raw)文件名获取其id
android 根据res文件夹下(如res/raw)文件名获取其id //测试是否能够获取其资源ID int treeId = mv.getResources().getIdentifier(fil ...
- AC自动机 (模板)
AC自动机是用来干什么的: AC自动机是用来解决多模匹配问题,例如有单词s1,s2,s3,s4,s5,s6,问:在文本串ss中有几个单词出现过,类似. AC自动机实现这个功能需要三个部分: 1.将所有 ...
- LoadRunner接口测试
[转自http://www.51testing.com/html/87/300987-805230.html] Action(){ //首先调用web_reg_find()这个注册函数,我们接口的正常 ...
- PCHMI工控组态开发视频教程
PCHMI是一款适合所有PLC工程师快速上手工控组态开发的控件 下面是视频教程链接 PCHMI工控组态 02-按钮的使用 PCHMI工控组态 03-数据显示器使用 PCHMI工控组态 04-标签控件的 ...