两个 swift 函数显着增加了编译时间 [英] Two swift functions increasing compiling time dramatically

查看:21
本文介绍了两个 swift 函数显着增加了编译时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

返回并阅读我的应用程序的构建日志后,似乎有一个奇怪的问题,即两个(相对)简单的函数都将编译时间分别增加了一分钟(分别为 58 秒和 53 秒).这可以在我的构建日志中看到:

After going back and reading my app's build logs, there seems to be a strange issue where two (relatively) simple functions are both increasing the compiling time by one minute each (58 & 53 seconds respectively). This can be seen in my build logs below:

这些函数在我的 CAAgeViewController 中,并且都引用了我的故事板中的 UISlider.他们确保最大和最小滑块彼此最多在 1 年内,并且任一函数将标签设置为18-24 年"或与此相关的内容.它们如下:

These functions are in my CAAgeViewController and both reference a UISlider in my storyboard. They make sure that both the max and min sliders are at most within 1 year of each other, and either function sets a label to "18-24 Years" or something to that respect. They are as follows:

@IBAction func minAgeChanged(_ sender: UISlider) {
    if round(minAgeSlider.value / 1) < round(maxAgeSlider.value / 1) - 1 {
        minAgeSlider.value = round(minAgeSlider.value / 1)
        ageLabel.text = String(Int(round(minAgeSlider.value / 1))) + "-" + String(Int(round(maxAgeSlider.value / 1))) + " Years"
    } else {
        minAgeSlider.value = round(maxAgeSlider.value / 1) - 1
        ageLabel.text = String(Int(round(minAgeSlider.value / 1))) + "-" + String(Int(round(maxAgeSlider.value / 1))) + " Years"

    }
}

@IBAction func maxAgeChanged(_ sender: UISlider) {
    if round(maxAgeSlider.value / 1) > round(minAgeSlider.value / 1) + 1 {
        maxAgeSlider.value = round(maxAgeSlider.value / 1)
        ageLabel.text = String(Int(round(minAgeSlider.value / 1))) + "-" + String(Int(round(maxAgeSlider.value / 1))) + " Years"
    } else {
        maxAgeSlider.value = round(minAgeSlider.value / 1) + 1
        ageLabel.text = String(Int(round(minAgeSlider.value / 1))) + "-" + String(Int(round(maxAgeSlider.value / 1))) + " Years"
    }
}

我不确定这里到底出了什么问题.任何帮助表示赞赏!

I am unsure what exactly is going wrong here. Any help is appreciated!

推荐答案

您的问题是链式加号.(它总是链式加号;好吧,不是总是而是总是......)

Your problem is the chained-plus. (It's always chained-plus; ok, not always but always…)

ageLabel.text = String(Int(round(minAgeSlider.value / 1))) + "-" + String(Int(round(maxAgeSlider.value / 1))) + " Years"

将其替换为:

ageLabel.text = "\(Int(round(minAgeSlider.value)))-\(Int(round(maxAgeSlider.value))) Years"

我很确定 /1 在这里对您没有帮助.round + Int 应该可以满足您的所有要求.

I'm fairly certain the /1 isn't helping you here. round + Int should do everything you meant.

这篇关于两个 swift 函数显着增加了编译时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆