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)
}
}
は本当に206ミリ秒、最長のビルド時ましたか?これは1秒未満です。それとも秒を言うのですか? –
郵便配達員のような外部ツールを使用して同じリクエストを試しましたか?あなたの誤りではないことを確かめるために、おそらくエンドポイントが遅いだけなのかもしれません。 – Ponja
Swiftコンパイラは大きなリテラル辞書を好きではありません。最初に空の辞書を作成し、それに値を追加してみてください。 '' parameters ["inspection_date"] = tf_inspection_date.text! 'のように次の値など。私はそれが楽しいわけではないが、通常は有効な回避策であることを知っている。 – Moritz