【发布时间】:2015-05-01 15:05:44
【问题描述】:
我正在使用一个数组来返回是否选择了我的任何嵌套按钮。
为了方便我,我做了这个内部函数。
一切都变得非常缓慢。
我去掉了辅助函数,构建时间几乎是瞬间完成的。
不确定为什么类型推断在这里不起作用? (如果这是问题)
我已阅读此Why is swift compile time so slow?,但我还不知道为什么这些特定的行会停滞不前。
func areAnyAMPMButtonsSelected() -> [Bool] {
func nilToBool(optional: AppointmentDatePickerAMPMButton?) -> Bool {
return (optional != nil) ? optional!.selected : false
}
return [
nilToBool(self.sundayAMButton),
nilToBool(self.mondayAMButton),
nilToBool(self.tuesdayAMButton),
nilToBool(self.wednesdayAMButton),
nilToBool(self.thursdayAMButton),
nilToBool(self.fridayAMButton),
nilToBool(self.saturdayAMButton),
nilToBool(self.sundayPMButton),
nilToBool(self.mondayPMButton),
nilToBool(self.tuesdayPMButton),
nilToBool(self.wednesdayPMButton),
nilToBool(self.thursdayPMButton),
nilToBool(self.fridayPMButton),
nilToBool(self.saturdayPMButton)
]
编译器停在这里
1. While type-checking 'getValidTimesArray' at /Users/gustavo/Projects/vm/yips-ios/YIPS-iOS/AppointmentDatePickerView.swift:104:5
2。在 [/Users/gustavo/Projects/vm/yips-ios/YIPS-iOS/AppointmentDatePickerView.swift:110:16 - line:126:9] RangeText="[ nilToBool(self.sundayAMButton), nilToBool(self.mondayAMButton), nilToBool(self.tuesdayAMButton), nilToBool(self.wednesdayAMButton), nilToBool(self.thursdayAMButton), nilToBool(self.fridayAMButton), nilToBool(self.saturdayAMButton),
nilToBool(self.sundayPMButton),
nilToBool(self.mondayPMButton),
nilToBool(self.tuesdayPMButton),
nilToBool(self.wednesdayPMButton),
nilToBool(self.thursdayPMButton),
nilToBool(self.fridayPMButton),
nilToBool(self.saturdayPMButton)
]"
【问题讨论】:
-
可能duplicate?
-
@Antonio - 在这种情况下,它的类型检查卡住了,而不是索引那么不同的问题。类型检查需要在这里清除,我想知道是否可以在没有一些淫秽重复的情况下完成
-
您是否尝试将数组减少到仅 3 或 4 个元素,仅用于测试?在我遇到编译缓慢的少数情况下,解决方案一直是将初始化分成多行。
-
不清楚你在问什么。什么样的答案会让你在这里开心?
-
@matt - 了解类型检查系统。否定的答案,比如这是不可能的,都是超级好的。我需要知道它是如何工作的。
标签: swift