apple / swift-algorithms

Commonly used sequence and collection algorithms for Swift
Apache License 2.0
5.98k stars 440 forks source link

Using combinations in a Playground #190

Open rfcohen opened 2 years ago

rfcohen commented 2 years ago

Xcode 14, target iOS is 14.1

When using a combinations in a playground, I get this error -

error: Test.playground:301:30: error: value of type '[Double]' has no member 'combinations' for combo in combos.combinations(ofCount: 1...4) {

Now where else to turn. It seems that the package is successfully added to the project. The playground is in the project with the dependancy added.

The import statement is there. import Algorithms

Growl, not sure who else to ask?

hatembr commented 1 year ago

I got the same issue, it kept complaining about combinations. My playground is in a workspace that has the package swift-algorithms added to it.

Running Xcode 14.2 (14C18) and target set to iOS 16.2

After constantly failing, it randomly worked. But I can't explain how or why my laptop froze and I had to restart and then after doing so it went back to throwing me this error and not recognizing the combinations func.

import Algorithms

let numbers = [10, 20, 30, 40]
for combo in numbers.combinations(ofCount: 2) {
    print(combo)
}

gives

expression failed to parse:
error: Punnett.playground:4:22: error: value of type '[Int]' has no member 'combinations'
for combo in numbers.combinations(ofCount: 2) {
             ~~~~~~~ ^~~~~~~~~~~~

Any help is appreciated. Thanks.

rfcohen commented 1 year ago

The solution I found is in File->Packages

Choose Reset/Resolve and Update packages in various orders until it works.

-Rob

On Dec 27, 2022, at 8:45 PM, HBR @.***> wrote:

I got the same issue, it kept complaining about combinations. My playground is in a workspace that has the package swift-algorithms added to it.

Running Xcode 14.2 (14C18) and target set to iOS 16.2

After constantly failing, it randomly worked. But I can't explain how or why my laptop froze and I had to restart and then after doing so it went back to throwing me this error and not recognizing the combinations func.

import Algorithms

let numbers = [10, 20, 30, 40] for combo in numbers.combinations(ofCount: 2) { print(combo) } gives

expression failed to parse: error: Punnett.playground:4:22: error: value of type '[Int]' has no member 'combinations' for combo in numbers.combinations(ofCount: 2) {


Any help is appreciated.
Thanks.

—
Reply to this email directly, view it on GitHub <https://github.com/apple/swift-algorithms/issues/190#issuecomment-1366306511>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AALBS7ZC3FA5YAEXV2FDX6TWPOLTVANCNFSM6AAAAAAQSHT42M>.
You are receiving this because you authored the thread.
hatembr commented 1 year ago

@rfcohen that worked. Hopefully this gets resolved in more correct way, but until then this workaround should do the job. Thanks!