因此,在诊断出我的代码后,我将其缩小到一行,这导致我的整个项目需要几秒钟到几小时才能构建。我将参数传递给Alamofire以发送到我的API,但它们会导致Xcode永远索引/构建。谁能找出原因?
有问题的行
var credit_union : String = ""
var activity : String = ""
var task : String = ""
var billing_options : String = ""
var sun : Float = 0
var mon : Float = 0
var tue : Float = 0
var wed : Float = 0
var thu : Float = 0
var fri : Float = 0
var sat : Float = 0
var total : Float = 0
var sun_notes : String = ""
var mon_notes : String = ""
var tue_notes : String = ""
var wed_notes : String = ""
var thu_notes : String = ""
var fri_notes : String = ""
var sat_notes : String = ""
let approval : String = ""
let department : String = currentUser.department
let submitted : String = "Not Submitted"
let date_of_time : Date = startDatePassing + 1.day
let id : Int = 0
let parameters: Parameters = [
"credit_union": credit_union,
"activity": activity,
"task" : task,
"billing_options" : billing_options,
"sun" : sun,
"mon" : mon,
"tue" : tue,
"wed" : wed,
"thu" : thu,
"fri" : fri,
"sat" : sat,
"total" : total,
"sun_notes" : sun_notes,
"mon_notes" : mon_notes,
"tue_notes" : tue_notes,
"wed_notes" : wed_notes,
"thu_notes" : thu_notes,
"fri_notes" : fri_notes,
"sat_notes" : sat_notes,
"approval" : approval,
"department" : department,
"submitted" : submitted,
"date_of_time" : date_of_time
]
答案 0 :(得分:3)
构建需要很长时间,因为有一个大字典文字。您可以尝试使用dict[key] = value
语法创建字典。
let parameters: Parameters = {
var dict = Parameters()
dict["credit_union"] = credit_union
dict["activity"] = activity
// the rest of the KVPs goes here
return dict
}()
答案 1 :(得分:2)
我通常通过一次构建一个问题来解决这类问题(我也看到它发生在复杂的字符串,长数组等)。 e.g。
var parameters: Parameters = ["credit_union": credit_union]
parameters["activity"] = activity
// etc.