在将代码重构或分解成较小的部分时,我真的需要帮助。我的Xcode甚至无法构建项目,因为它太复杂了。
表达过于复杂,无法在合理的时间内解决;考虑将表达式分成不同的子表达式
我不能分解成小块,因为我必须将UITextField的结果分配给该函数以将其推送到BackEnd。代码太乱了。
/ *这就是我为Bools和选择分配值的地方* /
@objc func handleSaveMZHD()
var NalichieTehPasportBol: Bool = false
if NalichieTehPasportResponse.text == "Да"{
NalichieTehPasportBol = true
} else if NalichieTehPasportResponse.text == "Нет"{
NalichieTehPasportBol = false
}
var NalichieElektroLambiBol: Bool = false
if (ElektroLampiResponse.text == "Да"){
NalichieElektroLambiBol = true
} else if ElektroLampiResponse.text == "Нет"{
NalichieElektroLambiBol = false
}
var NalichieLiftaBol: Bool = false
if NalichieLiftaResponse.text == "Да"{
NalichieElektroLambiBol = true
} else if NalichieLiftaResponse.text == "Нет"{
NalichieElektroLambiBol = false
}
var AktTehObsledSelection: Int = 0
if AktTehnObsledovaniyaResponse.text == "аварийный"{
AktTehObsledSelection = 1
} else if self.AktTehnObsledovaniyaResponse.text == "Не аварийный"{
AktTehObsledSelection = 2
}
var BalansPrinadlejnostiSel: Int = 0
if BalansPrinadlejResponse.text == "Государственная Собственность" {
BalansPrinadlejnostiSel = 1
} else if BalansPrinadlejResponse.text == "Частная Собственность" {
BalansPrinadlejnostiSel = 2
}
var OblicovkaSel: String = ""
if OblicovkaResponse.text == "Монолит"{
OblicovkaSel = "monolith"
}else if OblicovkaResponse.text == "Кирпич"{
OblicovkaSel = "brick"
}else if OblicovkaResponse.text == "Блоки"{
OblicovkaSel = "blocks"
}else if OblicovkaResponse.text == "Облицовка"{
OblicovkaSel = "facing"
}
/* That's function itself to push all that information to BackEnd */
updaTeRecord(o_model: "property.building", id: 207, attrs: [
"street": ulicaResponse.text,
"parking_area": PlowadParkingaResponse.text,
"builded_at": GodPostroikiResponse.text,
"all_size": Int(ObwayaPlowadDomaResponse.text!),
"land_size": Int(ObwayaPlowadUchastkaResponse.text!),
"apartment_amount": Int(KolvoKvartirResponse.text!),
"porch_amount": Int(KolvoPodezdovResponse.text!),
"level_amount": KolvoEtajeiResponse.text,
"is_tech_passport" : NalichieTehPasportBol,
"entrance_state": SostoyaniePodezdResponse.text,
"entrance_energy_saving_lamps": NalichieElektroLambiBol,
"entrance_windows_count": KolvoOkonResponse.text,
"entrance_windows_material": MaterialOkonResponse.text,
"lift_provided": NalichieLiftaBol,
"conclusion_of_technical_inspection": AktTehObsledSelection,
"lift_amount": Int(KolvoLiftovResponse.text!),
"lift_installed_at": DataUstanovkiLiftaResponse.text,
"lift_lifetime": SrokEkspluatLiftaResponse.text,
"lift_last_checked": DataPoslObslLiftaResponse.text,
"lift_company": ObslujOrganizaciyaResponse.text,
"lift_payment_method": TipOplatiLiftaResponse.text,
"power_consumption": PotreblyaemayaMownostResponse.text,
"registration_of_condominium": RegestraciyaKondominimumaResponse.text,
"date_of_condominium": DataRegestraciyaKondominimumaResponse.text,
"inventory_number": InvertarniiNomerResponse.text,
"cadastral_number": KadastroviiNomerResponse.text,
"date_of_the_last_overhaul": PosledniiKapitalniiRemontResponse.text,
"energy_efficiency": KlassEnergoResponse.text,
"house_balance": BalansPrinadlejnostiSel,
"definition_isystem": InformacionnayaSystemaResponse.text,
"ip_address_isystem": InformacionnayaIPadressResponse.text,
"last_energy_audit_at": EnergoAudiotResponse.text,
"number_of_sections": KolvoSekciiResponse.text,
"service_life_of_the_building": SrokSlujbZdaniyaResponse.text,
"depreciation": IznosMZHDResponse.text,
"house_walls": OblicovkaSel
]) { (result) in
print(result)
}
答案 0 :(得分:1)
尝试像这样将您的通话分散到updaTeRecord(o_model:id:attrs:completion:)
:
let myAttributes: [String: Any] = [
"street": ulicaResponse.text,
"parking_area": PlowadParkingaResponse.text,
"builded_at": GodPostroikiResponse.text,
//...
"service_life_of_the_building": SrokSlujbZdaniyaResponse.text,
"depreciation": IznosMZHDResponse.text,
"house_walls": OblicovkaSel
]
updaTeRecord(o_model: "property.building", id: 207, attrs: myAttributes) { (result) in
print(result)
}
在大多数情况下,这可能会更稳定(编译时不会出现类似问题)
var myAttributes: [String: Any] = [:]
myAttributes["street"] = ulicaResponse.text
myAttributes["parking_area"] = PlowadParkingaResponse.text
myAttributes["builded_at"] = GodPostroikiResponse.text
//...
myAttributes["service_life_of_the_building"] = SrokSlujbZdaniyaResponse.text
myAttributes["depreciation"] = IznosMZHDResponse.text
myAttributes["house_walls"] = OblicovkaSel
updaTeRecord(o_model: "property.building", id: 207, attrs: myAttributes) { (result) in
print(result)
}