Swift 中 Bool var 和 func 命名约定的混乱

Saz*_*han 4 refactoring naming-conventions ios swift

我正在开发 iOS/Swift 应用程序。看到BoolGoogle 提供的变量和函数命名约定(https://google.github.io/swift/)后,我很困惑。因为 Swift 本身遵循简单的副词,这在 Google 的建议中没有提到,即

https://developer.apple.com/documentation/swift/array/2945493-contains

命名返回 Bool 的函数的正确方法应该是什么?

Option 1. matches(string: String) -> Bool
Option 2. isMatched(string: String) -> Bool
Run Code Online (Sandbox Code Playgroud)

我更喜欢自己将其命名为 ,matches但我的团队成员希望将其命名为isMatched

Moj*_*ini 6

来自Swift API 设计指南

当布尔方法和属性的使用是非可变的时,布尔方法和属性的使用应该被理解为关于接收者的断言,例如x.isEmpty, line1.intersects(line2)

所以他们都是正确的。基金会还同时使用两者:例如

12.isMultiple(of: 2)
[12].contains(2)

// and more e.g.
"accept".hasPrefix("a")
Run Code Online (Sandbox Code Playgroud)

唯一重要的是要正确阅读。