简单功能的构建时间长

时间:2016-12-05 16:48:46

标签: ios optimization swift3 alamofire

我想知道为什么我的功能需要花费很多时间来构建。对我来说,最长的时间是206.1毫秒,超过3分钟!

187721.1ms InspectionViewController.swift:423:17    @IBAction @objc func btnSaveTouch(_ sender: Any)

我正在寻找一些优化,但找不到任何合理的理由,为什么我的功能太慢了。

我在这里使用Alamofire,以及几个字段(文本字段,文本视图和2个x开关)

代码看起来像这样:

@IBAction func btnSaveTouch(_ sender: Any) {

        var two_storeys = ""
        var legal_height_downstairs = ""

        if s_two_storeys.isOn {
            two_storeys = "Yes"
        } else {
            two_storeys = "No"
        }

        if s_legal_height_downstairs.isOn {
            legal_height_downstairs = "Yes"
        } else {
            legal_height_downstairs = "No"
        }

        let parameters : Parameters = [
            "inspection_date" : tf_inspection_date.text!,
            "property_type" : tf_property_type.text!,
            "beds" : tf_beds.text!,
            "baths" : tf_baths.text!,
            "cars" : tf_cars.text!,
            "our_price_min" : tf_our_price_min.text!,
            "our_price_max" : tf_our_price_max.text!,
            "max_rent" : tf_rent_max.text!,
            "min_rent" : tf_rent_min.text!,
            "upfront_max": tf_upfront_max.text!,
            "character": tf_character.text!,
            "character_years": tf_character_years.text!,
            "character_uers": tf_character_year.text!,
            "build_construction": tf_build_construction.text!,
            "roof_material":  tv_roof_material.text!,
            "house_on": tf_house_on.text!,
            "two_storeys": two_storeys,
            "legal_height_downstairs": legal_height_downstairs,
            "legal_height_downstairs_value" : tv_legal_height_downstairs_value.text!

        ]

        Alamofire.request(saveUrl, method: .post, parameters: parameters).responseJSON { response in

            _ = handleError(response: response)


        }

    }

1 个答案:

答案 0 :(得分:0)

所以Eric Aya是对的。现在这个函数的编译时间是19.9ms。下面的工作代码。

    var paramaters : Parameters = [:]

    paramaters["inspection_date"] = tf_inspection_date.text!
    paramaters["property_type"] = tf_property_type.text!
    paramaters["beds"] = tf_beds.text!
    paramaters["baths"] = tf_baths.text!
    paramaters["cars"] = tf_cars.text!
    paramaters["our_price_min"] = tf_our_price_min.text!
    paramaters["our_price_max"] = tf_our_price_max.text!
    paramaters["max_rent"] = tf_rent_max.text!
    paramaters["min_rent"] = tf_rent_min.text!
    paramaters["upfront_max"] = tf_upfront_max.text!
    paramaters["character"] = tf_character.text!
    paramaters["character_years"] = tf_character_years.text!
    paramaters["character_uers"] = tf_character_year.text!
    paramaters["build_construction"] = tf_build_construction.text!
    paramaters["roof_material"] = tv_roof_material.text!
    paramaters["house_on"] = tf_house_on.text!
    paramaters["two_storeys"] = two_storeys
    paramaters["legal_height_downstairs"] = legal_height_downstairs
    paramaters["legal_height_downstairs_value"] = tv_legal_height_downstairs_value.text!

回答杰里米的问题 - 是的,代码很简单:

enter image description here