作者热门文章
- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
我在 swift3 中有以下代码,我正在使用 swift lint 对代码进行 linting。给出代码如下:
func selectedMenuInLoggedOutState(sender: UIButton) {
switch sender.tag {
case 1:
if let menu = LeftGuestMenu(rawValue: 0) {
self.changeGuestViewController(menu)
}
case 2:
if let menu = LeftGuestMenu(rawValue: 1) {
self.changeGuestViewController(menu)
}
case 3:
if let menu = LeftGuestMenu(rawValue: 2) {
self.changeGuestViewController(menu)
}
case 4:
if let menu = LeftGuestMenu(rawValue: 3) {
self.changeGuestViewController(menu)
}
case 5:
if let menu = LeftGuestMenu(rawValue: 4) {
self.changeGuestViewController(menu)
}
case 6:
if let menu = LeftGuestMenu(rawValue: 5) {
self.changeGuestViewController(menu)
}
default:
break
}
}
swift lint 生成“违反圈复杂度”警告。为什么会出现此警告?如何解决?
最佳答案
该方法太复杂。但不是重写代码,您可以从 cyclomatic_complexity
计算中排除 switches
(因为它们完全可读),如下所示:
cyclomatic_complexity:
ignores_case_statements: true
关于ios - 圈复杂度违规 : Function should have complexity 10 or less: currently complexity equals 13 (cyclomatic_complexity),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45890629/
我是一名优秀的程序员,十分优秀!