use*_*522 6 xcode ios swift swift3
我已经将我的Swift 2.3项目转换为swift 3.现在编译器不再抛出任何错误,但它会继续编译.CPU就像是100%,如果你不停止它,它会持续编译50分钟或更长时间.
Xcode一直在说建筑.. | 编译Swift源文件
在构建日志中,它始终停在相同的swift文件上.swift文件只是简单的模型类,所以我不知道问题是什么.
我在swift 2中遇到了同样的问题,但这是由??运营商引起的.我重构了代码以删除??运算符,因此它不再是这个.
我怎样才能找出减慢编译时间的原因?
我的模特看起来都一样:
class Test: InputContract {
var appointmentDate: Date!
var startTime: String!
var endTime: String!
var registerDescription: String!
var subjectKey: String!
var channelCode: String!
var relationManagerHrId: String = ""
var employeeUserCode: String = ""
var smsReminderMobileNumber: String = ""
var smsReminderMobileNumberSequence: String!
var contactPhoneNumber: String = ""
var contactPhoneNumberSequence: String!
var smsReminder: Bool = false
override func retrieveInputDictionary() -> NSDictionary {
return ["description" : self.registerDescription, "appointmentDate" : Utils.formattedDate(self.appointmentDate),
"startTime" : self.startTime, "endTime" : self.endTime, "subjectKey" : self.subjectKey, "channelCode" : self.channelCode, "smsReminder" : self.smsReminder ? "true" : "false", "relationManagerHrId" : self.relationManagerHrId, "employeeUserCode" : self.employeeUserCode,
"smsReminderMobileNumber" : self.smsReminderMobileNumber, "contactPhoneNumber" : self.contactPhoneNumber, "smsReminderMobileNumberSequence" : self.smsReminderMobileNumberSequence, "contactPhoneNumberSequence" : self.contactPhoneNumberSequence
]
}
}
Run Code Online (Sandbox Code Playgroud)
InputContract是:
protocol InputDictionaryMapper {
func retrieveInputDictionary() -> NSDictionary
func retrievePublicInputDictionary() -> NSDictionary
}
class InputContract: Model, InputDictionaryMapper {
func retrieveInputDictionary() -> NSDictionary {
fatalError("Each inputContract implementation must implement it's own method: \(NSStringFromClass(type(of: self)))")
}
func retrievePublicInputDictionary() -> NSDictionary {
fatalError("Each inputContract implementation must implement it's own method: \(NSStringFromClass(type(of: self)))")
}
required init(json: JSON) {
fatalError("init(json:) has not been implemented")
}
override init() {
super.init()
}
}
Run Code Online (Sandbox Code Playgroud)
而model只是一个基类,它也有json的另一个init.
当我在构建日志上运行分析器时,我所有的模型都花了很长时间来创建NSDictionary.但为什么?
所以问题是我们创建了很多这样的字典:
let dict = ["key": value, "key2": value2]
Run Code Online (Sandbox Code Playgroud)
如果你重写为
var dict: [String: Any] = [String: Any]()
dict["key"] = value
dict["key2"] = value2
Run Code Online (Sandbox Code Playgroud)
然后编译器神奇地每个模型只需要15到20毫秒而不是每个模型2000毫秒.
您可以使用构建时间分析器应用程序自己尝试:-)
| 归档时间: |
|
| 查看次数: |
2267 次 |
| 最近记录: |