2016-12-05 9 views
0

なぜ私の関数がビルドに時間がかかるのだろうと思っています。私にとって最長の時間は206.1msです。これは3分以上です!シンプルな関数のビルド時間が長い

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

私はいくつかの最適化を探していましたが、私の機能は非常に遅いですなぜ合理的な理由を見つけることができません。

私は、コードをここにAlamofireを使用して、フィールドのカップル(テキストフィールド、テキストビュー、および2×スイッチ)

てるは以下のようになります。

@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

は本当に206ミリ秒、最長のビルド時ましたか?これは1秒未満です。それとも秒を言うのですか? –

+0

郵便配達員のような外部ツールを使用して同じリクエストを試しましたか?あなたの誤りではないことを確かめるために、おそらくエンドポイントが遅いだけなのかもしれません。 – Ponja

+1

Swiftコンパイラは大きなリテラル辞書を好きではありません。最初に空の辞書を作成し、それに値を追加してみてください。 '' parameters ["inspection_date"] = tf_inspection_date.text! 'のように次の値など。私はそれが楽しいわけではないが、通常は有効な回避策であることを知っている。 – Moritz

答えて

0

ので、エリック綾は正しかったです。現在、この関数のコンパイル時間は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

関連する問題