gpt4 book ai didi

swift - 代码导致 Swift 索引消耗大量内存

转载 作者:行者123 更新时间:2023-11-30 12:52:37 24 4
gpt4 key购买 nike

我有下面的代码旋转网,当 xcode 尝试索引时,它会导致 SourceKitService 消耗大量内存,并且将继续这样做,除非进程被杀死(在我杀死它之前达到超过 20GB)。

let key = ""
let register = "";


var vpn:String?
var password:String?

var taxDueString:String?
var motDueString:String?
var makeString:String?
var dateString:String?
var manufactureString:String?
var ccString:String?
var co2String:String?
var fuelString:String?
var exportString:String?
var statusString:String?
var colourString:String?
var approvalString:String?
var wheelplanString:String?
var revenueString:String?

var parkingIsOn:Bool?
var motIsOn:Bool?
var tollsIsOn:Bool?
var insuranceIsOn:Bool?
var fuelIsOn:Bool?
var partsIsOn:Bool?
var trafficIsOn:Bool?

@IBOutlet weak var firstNameText: UITextField!
@IBOutlet weak var lastNameText: UITextField!
@IBOutlet weak var mobileText: UITextField!
@IBOutlet weak var emailText: UITextField!
@IBOutlet weak var confirmEmailText: UITextField!
...
Just.post(
register,
data: ["key": key, "vrn": vpn, "password": password, "taxDue": taxDueString, "motDue": motDueString, "make": makeString, "date": dateString, "manufacture": manufactureString, "cc": ccString, "co2": co2String, "fuel": fuelString, "export": exportString, "status": statusString, "colour": colourString, "approval": approvalString, "wheelplan": wheelplanString, "revenue": revenueString, "featureParking": parkingIsOn, "featureMot": motIsOn, "featureTolls": tollsIsOn, "featureInsurance": insuranceIsOn, "featureFuel": fuelIsOn, "featureParts": partsIsOn, "featureTraffic": trafficIsOn, "firstname": firstNameText.text, "lastname": lastNameText.text, "mobile": mobileText.text, "email": emailText.text ]
) { r in
if r.ok {
let json = JSON(data: r.content!);
let success = json["success"].intValue

print(json)

if (success == 1){
let defaults = UserDefaults.standard
defaults.setValue(true, forKey: "logged")
defaults.setValue(json["ID"].intValue, forKey: "ID")
defaults.synchronize()

DispatchQueue.main.async { [unowned self] in
self.performSegue(withIdentifier: "registerToDash", sender: nil)
}

}else{
DispatchQueue.main.async { [unowned self] in
self.showError(error: json["error"].stringValue)
}
return
}

}
}

我可以看到是数据行导致了问题,因为当我将其注释掉时,所有索引都很好。

data: ["key": key, "vrn": vpn, "password": password, "taxDue": taxDueString, "motDue": motDueString, "make": makeString, "date": dateString, "manufacture": manufactureString, "cc": ccString, "co2": co2String, "fuel": fuelString, "export": exportString, "status": statusString, "colour": colourString, "approval": approvalString, "wheelplan": wheelplanString, "revenue": revenueString, "featureParking": parkingIsOn, "featureMot": motIsOn, "featureTolls": tollsIsOn, "featureInsurance": insuranceIsOn, "featureFuel": fuelIsOn, "featureParts": partsIsOn, "featureTraffic": trafficIsOn, "firstname": firstNameText.text, "lastname": lastNameText.text, "mobile": mobileText.text, "email": emailText.text ]

我似乎看不出上述代码有任何问题,但其中的某些内容导致索引崩溃/行为异常

最佳答案

我的猜测是它无法推断如此大的字典文字的类型。尝试将其定义为类型常量,然后将其传递到函数中。

关于swift - 代码导致 Swift 索引消耗大量内存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40774650/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com