There is a typo in the comments for this code:
numberOfPermutations(4, setSize: 2) // 12
numberOfPermutations(6, setSize: 2) // 20
numberOfPermutations(6, setSize: 6) // 720
The number of permutations of size 2 from a domain of 6 elements is 30.
Got error after input code: let exampleCombinations = [âAâ, âBâ, âCâ].combinations(ofCount: 2)
How to fix it?
XCode 12.4, Swift 5
error: Combinations.xcplaygroundpage:45:43: error: value of type â[String]â has no member âcombinationsâ
let exampleCombinations = [âAâ, âBâ, âCâ].combinations(ofCount: 2)
~~~~~~~~~~~~~~~ ^~~~~~~~~~~~
Hello @eggmanqi, thank you for mentioning this right away.
I managed to reproduce this right away even on the âfinalâ project with Xcode 12.4. I believe something changed in how linking works between the two. no idea what or why but anyway I managed to find a quick solution and Iâll update the getting started part right away to match.
After you add the algorithms Swift Package do the following:
Select the project file from the navigator, then select the target âUmbrellaFrameworkâ. Select âBuild Phasesâ and add the âAlgorithmsâ package as a dependency.
In the Playground files remove the âimport Algorithmsâ line at the top. this means you should have only ONE include not TWO.
In either of the two swift files in the project (âSampleData.swiftâ or âUtilities.swiftâ) add âimport Algorithmsâ. This is very important. without it the dependency step wonât do much for the playground.
This will make it work and playgrounds will be happy.
If you keep the two includes it wonât work. which is odd imho.
Let me know if you managed to get it to work.
@mr_berna thank you so much for spotting it :]
I updated the Getting Started section to include steps for adding Algorithms as a dependency to the framework target. This should resolve thee linking problem I the playground.
I also updated the final project so its working right away without the need of any changes.
Updating my earlier comment: It doesnât matter if the Algorithms is included in the playground page or not as long as it is present in the dependencies AND its inclusion in mentioned in one of the code files in the framework.
I hope this resolved the issue for everyone :]

Wooo it works now~ thanks update
1 Like
In the âChunkedâ playground, thereâs an omission in the âbeforeâ code. Ironically, it serves to illustrate the advantage of using Swift Algorithms: No more forgetting to flush the last result when constructing a variable from an iteration over a set!
Specifically, after âfor (movie, year) in marvelMovieswithYears {âŠ}â, you need to add a final âgroupedMovies.append(currentGroup)â. Otherwise all those great movies from 2019 will be skipped. 