Krzysztof Romanowski
Krzysztof Romanowski

Reputation: 2184

Swift: Argument labels naming convention?

Suppose I want to hide/show an UI element using one function. What is the correct way to name it?

func changeRefreshControlVisibilityTo(_ isVisible: Bool) {}

or

func changeRefreshControlVisibility(to isVisible: Bool) {}

Do people have thoughts and/or references for this? Thanks!

Upvotes: 0

Views: 994

Answers (1)

user3581248
user3581248

Reputation: 1014

I personally wouldn't go with neither of these. The change part seems redundant to me, especially taking into account the fact, that it might not really change anything - let's say, that current visibility is false and you still can set false as the argument of this method.

So if you want to stick to word change, maybe something like that:

func changeRefreshControlVisibility() {}

or to me, even better one:

func toggleRefreshControlVisibility() {}

would be sufficient?

And if you want to openly communicate what value will the visibility have after using this method, why not simply:

func setRefreshControlVisible(_ isVisible: Bool) {}

Anyway, the API design guidelines for Swift are rather brief:

https://swift.org/documentation/api-design-guidelines/

So my general impression is that you should go with whatever suits you/your team best.

Upvotes: 1

Related Questions