Xcode 8.0 Swift 3.0 slow indexing and building

后端 未结 16 2107
天涯浪人
天涯浪人 2020-12-07 17:12

I\'ve installed Xcode 8.0 and converted Swift 2.2 to 3.0 (that process also took a lot of time, I just left my Mac running all night). I have not a big project (about 20 fil

相关标签:
16条回答
  • 2020-12-07 17:17

    Not that I think this is related to OP's issue, but XCode 8 for me recently slowed to a halt. I eventually found it was my mistake (and I remember inadvertently doing it) - I added XCode.app as a Framework reference. This essentially made XCode search and index the entire XCode.app folder. Once I saw the mistake and remove the Framework it came good again :)

    0 讨论(0)
  • 2020-12-07 17:20

    My problem was the dictionary. I had vary large dictionary.

    let values = ["address":addressTextField.text,"city":cityTextField.text,"zipCode":zipCodeTextField.text,"state":stateTextField.text,"pet":answerLabel.text,"rentStart":rentStartTextField.text,"rentEnd":rentEndTextField.text,"rent":rentTextField.text,"phone":phoneTextField.text,"email":emailTextField.text,"status":leaseStatusTextField.text,"bedrooms":bedroomTextField.text,"parking":parkingLabel.text,"furnish":furnishLabel.text,"utilities":utilitiesTextField.text,"laundry":laundryTextField.text,"paymentCycle":paymentCycleTextField.text,"note":noteTextView.text]
    

    I broke it down to:

            var values = ["address":addressTextField.text]
            values["city"] = cityTextField.text
            values["zipCode"] = zipCodeTextField.text
            values["state"] = stateTextField.text
            values["pet"] = answerLabel.text
            values["rentStart"] = rentStartTextField.text
            values["rentEnd"] = rentEndTextField.text
            values["rent"] = rentTextField.text
            values["phone"] = phoneTextField.text
            values["email"] = emailTextField.text
            values["status"] = leaseStatusTextField.text
            values["bedrooms"] = bedroomTextField.text
            values["parking"] = parkingLabel.text
            values["furnish"] = furnishLabel.text
            values["utilities"] = utilitiesTextField.text
            values["laundry"] = laundryTextField.text
            values["paymentCycle"] = paymentCycleTextField.text
            values["note"] = noteTextView.text
            values["owner"] = userID
    
    0 讨论(0)
  • 2020-12-07 17:22

    What solves this for me is using keys to set dictionary values

    let dict: [string:any]()
    dict["key"] = "value"
    dict["key1"] = "value"
    dict["key2"] = "value"
    return dict
    

    If you have a long dictionary it may or may not cause a compile loop resulting in long build times. Anything longer than 8 keys should be set way.

    0 讨论(0)
  • 2020-12-07 17:26

    Go to project settings, then Editor > Add Build Setting > Add User-Defined Setting, and add the following:

    SWIFT_WHOLE_MODULE_OPTIMIZATION = YES
    

    Adding this flag dropped our clean-build compile times from 7 mins to 65s for a 40KLOC swift project, miraculously. Also can confirm 2 friends have seen similar improvements on enterprise projects.

    I can only assume this is some kind of bug in Xcode 8.0

    0 讨论(0)
  • 2020-12-07 17:27

    I solved the problem by commenting all files and then removing comments one by one. I found that the problem is still in the array declaration as described here.

    I had code like this and project was not indexing:

    class {
        var first: String!
        var second: String!
        var third: String!
        var fourth: String!
        var fifth: String!
    
        func abc() -> [String] {
            var array = [first, second, third, fourth, fifth]
        }
    }
    

    I've changed it to this and indexing started working:

    class {
        var first: String!
        var second: String!
        var third: String!
        var fourth: String!
        var fifth: String!
    
        func abc() -> [String] {
            var array = [first]
    
            array.append(second)
            array.append(third)
            array.append(fourth)
            array.append(fifth)
        }
    }
    
    0 讨论(0)
  • 2020-12-07 17:28

    I had similar problem and followed this guide to debug : http://irace.me/swift-profiling My problem was i had nil coalescing operator in some strings for example:

    let name = "\(someString ?? "")"
    

    and four methods with this were causing 2 min additional building time.

    0 讨论(0)
提交回复
热议问题