You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Basically it is now unnecessarily difficult to call NSArray indexesOfObjects. The reason is that Swift sees the passingTest: parameter as ambiguous. Now, you might say: huh? Ambiguous with what? Well, it's rather subtle. Here's the detailed complaint from the compiler:
The nameless parameter in the second method has a default value, and both methods have a `passingTest` parameter, so in the absence of further information, our code could now be calling either of them.
This analysis suggests (rightly) that we can worm our way out of the difficulty by saying:
Yecch! What is the point of having an optional parameter (a parameter with a default value) if you have to supply it anyway? How did we get ourselves into this mess in the first place?
The answer is that Objective-C has two perfectly separate methods:
indexesOfObjectsWithOptions:...
and
indexesOfObjectsPassingTest:...
A moment's thought will reveal that Swift renamification has conflated these two methods into one. It is therefore impossible to call indexesOfObjectsPassingTest — it is effectively stricken from the field. Only indexesOfObjectsWithOptions can be called.
This could easily be resolved by giving the options parameter an explicit label. We would then have indexesOfObjects(options:... ) and indexesOfObjects(passingTest:... ) and all would be well.
The text was updated successfully, but these errors were encountered:
I see now that I also reported this, rather less perceptively, as rdar://problem/25770004 — it has taken me a while to understand why Swift thinks there's an ambiguity
Environment
Xcode 7.3.1 and any recent Swift 3 toolchain
Additional Detail from JIRA
md5: 1d39ecdeb1ffe00f63e421b47bc0eb59
is duplicated by:
relates to:
Issue Description:
The following code doesn't compile in any recent toolchain, due to issue with renamification and the rules for Swift default parameters:
Basically it is now unnecessarily difficult to call NSArray indexesOfObjects. The reason is that Swift sees the
passingTest:
parameter as ambiguous. Now, you might say: huh? Ambiguous with what? Well, it's rather subtle. Here's the detailed complaint from the compiler:The nameless parameter in the second method has a default value, and both methods have a `passingTest` parameter, so in the absence of further information, our code could now be calling either of them.
This analysis suggests (rightly) that we can worm our way out of the difficulty by saying:
Yecch! What is the point of having an optional parameter (a parameter with a default value) if you have to supply it anyway? How did we get ourselves into this mess in the first place?
The answer is that Objective-C has two perfectly separate methods:
indexesOfObjectsWithOptions:...
and
indexesOfObjectsPassingTest:...
A moment's thought will reveal that Swift renamification has conflated these two methods into one. It is therefore impossible to call indexesOfObjectsPassingTest — it is effectively stricken from the field. Only indexesOfObjectsWithOptions can be called.
This could easily be resolved by giving the options parameter an explicit label. We would then have
indexesOfObjects(options:... )
andindexesOfObjects(passingTest:... )
and all would be well.The text was updated successfully, but these errors were encountered: