2023-05-03 11:06:20 +02:00
|
|
|
== Why is this an issue?
|
|
|
|
|
2021-06-08 14:23:48 +02:00
|
|
|
In the interests of clean code, getters should be implicit, rather than explicit for properties that have only getters.
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Noncompliant code example
|
2021-06-08 14:23:48 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,swift]
|
2021-06-08 14:23:48 +02:00
|
|
|
----
|
|
|
|
var luckyNumber: Int {
|
|
|
|
get { // Noncompliant
|
|
|
|
return 7
|
|
|
|
}
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
2023-05-03 11:06:20 +02:00
|
|
|
=== Compliant solution
|
2021-06-08 14:23:48 +02:00
|
|
|
|
2022-02-04 17:28:24 +01:00
|
|
|
[source,swift]
|
2021-06-08 14:23:48 +02:00
|
|
|
----
|
|
|
|
var luckyNumber: Int {
|
|
|
|
return 7
|
|
|
|
}
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
|
|
ifdef::env-github,rspecator-view[]
|
2021-06-08 15:52:13 +02:00
|
|
|
'''
|
2021-06-08 14:23:48 +02:00
|
|
|
== Comments And Links
|
|
|
|
(visible only on this page)
|
|
|
|
|
2023-05-25 14:18:12 +02:00
|
|
|
=== duplicates: S2962
|
|
|
|
|
|
|
|
=== on 8 Jul 2016, 19:29:50 Ann Campbell wrote:
|
|
|
|
https://github.com/github/swift-style-guide#prefer-implicit-getters-on-read-only-properties-and-subscripts
|
|
|
|
|
2021-06-08 14:23:48 +02:00
|
|
|
endif::env-github,rspecator-view[]
|