Is the Set and Get method naming convention wrong in Swift?

Are the naming conventions

"setNumber()" and "getNumber()" correct?

How do you intend to use it ? As func naming ? If so, yes, why would it not be correct ?

Note: don't forget to close your posts once you received a correct answer.

Your example names look like a getter and setter for a “property” (within the scope of an enclosing type not shown) which, if it were defined via normal property syntax, would be named simply number.

If possible and if it makes sense, consider using actual properties in cases like this, instead of separate getter and setter methods. Then callers can both read and write the property using very clean dot syntax like this:

myObject.number = 42
print(myObject.number)

Or if you are asking about naming free (global) functions, then it probably would be more common to name the getter like a property (with no prefix) and use the set prefix on the setter, like this:

setMaximumNumberOfGameLevels(42)
print(maximumNumberOfGameLevels())

You can find a number of good Swift coding convention guides online that cover this sort of thing in detail. Definitely worth checking out for anyone new to Swift.

Is the Set and Get method naming convention wrong in Swift?
 
 
Q