This is an annoyance, as opposed to anything critical.
I tend to use the standard headerdoc-style, in my Swift, like so:
/* ################################################# */
/**
Perform a server-based search.
- parameter specification: The search specification.
- parameter completion: A tail completion proc (may be called in any thread).
*/
public func meetingAutoRadiusSearch(minimumNumberOfResults inMinNumber: Int, specification inSpecification: SearchSpecification, completion inCompletion: @escaping QueryResultCompletion) {
The issue is that the compiler gives this warning:
Now, I always use "in..." parameters for my APIs. It helps me to keep track of what comes in from outside the function. I seldom use the external name.
However, consumers of the function are only interested in the external name.
I'm puzzled as to why Xcode doesn't want me to use these.
Is there some way to suppress the warning, or am I doing something else wrong, here?
(Yeah, I still have to document the first parameter, which is why I am looking at this, now).
According to the Swift API Design Guidelines, this is not how you should name parameters.
Choose parameter names to serve documentation. Even though parameter names do not appear at a function or method’s point of use, they play an important explanatory role.
Choose these names to make documentation easy to read. [...]
Parameter names are to "serve documentation", not (just) to serve you (the one who implements the function). Naming parameters this way is not "Swifty" at all.
If you want to mark which parameters are input, one way is to use a property wrapper like this:
@propertyWrapper
struct Input<T> {
let wrappedValue: T
}
public func someFunction(@Input x: Int, @Input y: Int) {
// ...
}
Though this doesn't make much sense to me - surely all non-inout parameters are "inputs"?
If you actually want a symbol that is named with a "in" prefix in your function, you can write a function body macro (here I called this InputParameterNames
) which, when used like this:
@InputParameterNames
public func someFunction(@Input x: Int, @Input y: Int) {
// ...
}
expands to
public func someFunction(@Input x: Int, @Input y: Int) {
let inX = x
let inY = y
// ...
}
It would find parameters that are marked @Input
in the parameters list, and generate a let
declaration for each of them. I am not going to write an implementation of this macro in this answer, because I do not endorse writing Swift in this way.
For how to silence a warning, see this post. It is currently impossible at the time of writing.