swift3 加了这一段[String:Any]后,编译超过二十分,该如何改

程式如下

override func viewDidLoad() {
    super.viewDidLoad()
    
    
    //var ProductNoArray = shoppingCarData.GoodsInfo.allKeys
    var tDictionary = [String:String]()
    var tnum:Int = 0
    for i in shoppingCarData.GoodsInfo {
        tnum = i.object(forKey: "num") as! Int
        tDictionary[i.object(forKey: "productno") as! String] = String(tnum)
    }
    
    let paramters = [
     "type":"do_order",
     "custno":UserInfoDictionary["CustNo"] as String!,
     "r_name":r_name,
     "r_phone":r_phone,
     "r_city":r_city,
     "r_address":r_address,
     "r_zip":r_zip,
     "total":shoppingCarData.TotalInt,
     "payment":shoppingCarData.PaymentInt,
     "shopwaypay":shoppingCarData.ShipWayPayInt,
     "discount":shoppingCarData.DiscountInt,
     //"shopway":shoppingCarData.ShipWayArray[shoppingCarData.ShipWayType],
     "shipwaytype":shoppingCarData.ShipWayType,
     "subtotal":shoppingCarData.SubTotalInt,
     "subtotalafterdiscount":shoppingCarData.SubTotalAfterDiscountInt,
     "CVSStoreID":CVSStoreID,
     "CVSAddress":CVSAddress,
     "CVSStoreName":CVSStoreName,
     "productnoarry":tDictionary,
     "savepersoninfobool":SavePersonalInfoBool,
     "savecreditcardinfobool":SaveCreditCardInfoBool,
     "be_invoice":BeInvoiceBool,
     "creditcardno":CreditCardInfoDictionary["CreditCardNo"],
     "creditname":CreditCardInfoDictionary["Name"],
     "creditmobile":CreditCardInfoDictionary["mobile"],
     "taxid":TaxInfoDictionary["taxid"],
     "taxtitle":TaxInfoDictionary["title"],
     "taxzip":TaxInfoDictionary["zip"],
     "taxaddress":TaxInfoDictionary["address"],
     "taxcity":TaxInfoDictionary["city"],
     "taxarea":TaxInfoDictionary["area"],
     "numarry":tDictionary
    ] as! [String:Any?]
     print(paramters)
     Alamofire.request(Config.val.AJAXURL, method: .post, parameters: paramters, encoding: URLEncoding.default).responseJSON { response in
        myFunc.MYFUNC.hideActivityIndicatory()
        print(response.result.value)
        if response.result.isFailure {
     
            myFunc.MYFUNC.showAlertWithMessage("交易失敗")
            return
        }
        print(response.result.value)
     
     
     
     }
    // Do any additional setup after loading the view.
}

图片描述

只要把 以下的 paramtes 给 mark掉,或是删除部份的元素 ,编译的时间就会缩短
请问以下的这段我要怎么改

阅读 3.4k
1 个回答

这是 Swift compiler 的一个老问题了,自动类型推导引起的bug。

改成:

let paramters : [String: String]= [
    /*你的内容*/
]

应该会好很多。另外,class里的属性加上 self 也能提高编译器的工作性能。

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏