Xcode continues to build on Swift 3

I converted my Swift 2.3 project to swift 3. Now the compiler no longer throws any errors, but it continues to compile. The CPU is similar to 100%, and it continues to compile for 50 minutes or more, unless you stop it.

Xcode continues to say Building .. | Compiling Swift Source Files

In the build log, it always dwells on the same fast files. Fast files are just model classes, so I don't know what the problem is.

I had the same problem in swift 2, but it was caused by a statement ?? . I reorganized the code to remove the operator ?? so that he could no longer be.

How can I find out what slows compilation time to infinity?

My models look the same:

 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 ] } } 

InputContract:

 protocol InputDictionaryMapper { func retrieveInputDictionary() -> NSDictionary func retrievePublicInputDictionary() -> NSDictionary } class InputContract: Model, InputDictionaryMapper { func retrieveInputDictionary() -> NSDictionary { fatalError("Each inputContract implementation must implement it own method: \(NSStringFromClass(type(of: self)))") } func retrievePublicInputDictionary() -> NSDictionary { fatalError("Each inputContract implementation must implement it own method: \(NSStringFromClass(type(of: self)))") } required init(json: JSON) { fatalError("init(json:) has not been implemented") } override init() { super.init() } } 

And the model is just a base class that has another init for json.

When I run the analyzer in the build log, all my models take a long time to create an NSDictionary. But why?

+6
source share
2 answers

So the problem was that we had many dictionaries created as follows:

 let dict = ["key": value, "key2": value2] 

If you rewrite it as

 var dict: [String: Any] = [String: Any]() dict["key"] = value dict["key2"] = value2 

then the compiler magically takes from 15 to 20 ms per model instead of 2000 ms per model.

You can try it yourself using the build time analyzer application :-)

+5
source

I had the same problem after moving the project to swift 3, but after a lot of R & D, I found a solution. This took time due to dictionaries and an array created without a data type.

0
source

All Articles