gpt4 book ai didi

ios - 圈复杂度违规 : Function should have complexity 10 or less: currently complexity equals 13 (cyclomatic_complexity)

转载 作者:技术小花猫 更新时间:2023-10-29 11:09:54 25 4
gpt4 key购买 nike

我在 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 生成“违反圈复杂度”警告。为什么会出现此警告?如何解决?

enter image description here

最佳答案

该方法太复杂。但不是重写代码,您可以从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com