SWIFTの間でデータを変換

1.swift開発 - NSDictionaryのとNSDataのシステム変換、辞書とデータHuzhuan

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

1、NSDictionaryの转たNSDataは
データを聞かせて:NSDataの= NSKeyedArchiver.archivedData(withRootObject:dataDic)asNSData

2、NSDataの转NSDictionaryのは
:として(!dataasデータで)DIC = NSKeyedUnarchiver.unarchiveObjectをしましょう!NSDictionaryの


3、NSDictionaryの转データは、
日付が=試してみましょう!JSONSerialization.data(withJSONObject:DIC、オプション:.prettyPrinted)

4は、データ转辞書は
、JSONは=試してみましょう!JSONSerialization.jsonObject(と:.mutableContainers:データ、オプション)など!辞書<文字列、文字列>

2.(NSStringのようUITextField.text).floatValue

複数行を表示するには、ラベルを使用します

民間 のfuncにsetData(showStr:文字列){

        DispatchQueue.main.async {

            自己 .leftTipLabelの.text = NSLocalizedString( "利用可能"、コメント: "")!+ "\ nは\ n"は+ NSLocalizedString( " 最小転送量"、コメント: "")+ "\ nは\ n"は+ NSLocalizedString( " 料金"コメント:" ")+ " \ nは\ n "は+ NSLocalizedString(" 到着量"コメント:"「)

        }

        自己 .leftTipLabel?.numberOfLines = 0

        聞かせて attributedStrM:NSMutableAttributedString = NSMutableAttributedString()

        attributedStrM.append(NSAttributedString(列:使用可能な属性:[NSAttributedString.Key.foregroundColor:UIColor.hexadecimalColor(16進: "#1 F1B11B")]))

        attributedStrM.append(NSAttributedString(列: "\(dataDict [" 通貨 "] stringValue.uppercased())。" + "\ n \ n" は、属性:[NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getTextColor()] ))

        attributedStrM.append(NSAttributedString(文字列:文字列(形式: "%の.3f"、((自己 .minWithdrawQuantity として文字列)として NSStringの).doubleValue)は、属性:[NSAttributedString.Key.foregroundColor:UIColor.hexadecimalColor(16進数:「# F1B11B ")]))

        attributedStrM.append(NSAttributedString(文字列:NSLocalizedString( "个" コメント: "")+ "\ nは\ nが" 属性:[NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

        VARのすべて:ダブル= 0

        だっダブル= 0:totalFeesは、

        もし 自己 .moneyTextField?の.text?.count == 0 {

            すべて= 0

            totalFees = 0

        } そう であれば自己 .moneyTextField!の.text!として .doubleValue <(NSStringの)自己 .minWithdrawQuantity として NSStringの).doubleValue {

            すべて= 0

            totalFees = 0

        } {

            

            聞かせて inputf:ダブル=ダブル((showStr として NSStringの).doubleValueを)

            聞かせて feesp:ダブル=ダブル((自己 .feeS として NSStringの).doubleValue)* inputf

            もし feesp>ダブル((自己 .firstFee として NSStringの).doubleValue){

                totalFees =ダブル((自己 .firstFee として NSStringの).doubleValue)

                すべて=(showStr として NSStringの).doubleValue - totalFees

                

            } {

                totalFees = feesp

                すべて=ダブル((showStr として NSStringの).doubleValue) - totalFees

                

            }

        }

        //料 "\(totalFees)"

        attributedStrM.append(NSAttributedString(文字列:文字列(形式: "%の.3f"、totalFees)、属性:[NSAttributedString.Key.foregroundColor:UIColor.hexadecimalColor(16進: "#1 F1B11B")]))

        attributedStrM.append(NSAttributedString(文字列:NSLocalizedString( "个" コメント: "")+ "\ nは\ nが" 属性:[NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

        

        到着//数// "\(すべて - totalFees)"

        attributedStrM.append(NSAttributedString(文字列:文字列(形式: "%の.3f"、全て)は、属性:[NSAttributedString.Key.foregroundColor:QBColor_Orange]))

        attributedStrM.append(NSAttributedString(文字列: "\(自己!.currentCurrencyは)"、属性:[NSAttributedString.Key.foregroundColor:ThemeColor.sharedInstance.getGrayTextWhiteColor()]))

        

        

        自己 .rightTipLabel?.textAlignment = NSTextAlignment.right

        自己 .rightTipLabel!.attributedText = attributedStrM

        自己 .rightTipLabel?.numberOfLines = 0

        

        

        DispatchQueue.main.async {

            セルフ!.bottomTipLabelの.text = NSLocalizedString( "手数料率"、コメント: "")+ " \(自己 .feeS)" + "" + NSLocalizedString( "シングル超えない"コメント: "")+ " \(自己 .firstFee) "+" \(自己 .currentCurrency!) "+ NSLocalizedString("どのくらいの手数料"コメント:"「)

        }

        

        自己 .view.layoutIfNeeded()

    }

 

おすすめ

転載: www.cnblogs.com/sundaysme/p/11600689.html