Swift Package Collections
With Package Collections you can quickly look up and add a Swift Package to your project in Xcode 13. Let's use the new Swift Algorithms package as an example - this package provides implementations for algorithms often needed for everyday programming tasks. Adding such a package is now only two clicks away:
Task
Display a list of food items grouped in chunks:
Required knowledge
You need basic knowledge of Swift and SwiftUI and you need to know how to → use Swift Packages in Xcode projects.
Steps
-
Make sure you're using Xcode 13, this example uses new features in Xcode 13 (this was last tested with Xcode 13 beta 3).
-
Download and open the starter project for the example project: FoodChoiceExample.
-
In FoodChoiceView, manually write an import for the Algorithms package. Build the project to get a compiler error which offers to add the package to the project for you:
Get the swift-algorithms package from the package collection - Xcode comes pre-configured with a Package collection with the packages from Apple:
-
Add a VStack / ForEach to the view and use the method chunks(ofCount:) from the Swift algorithm package to group the food items in chunks:
Additional Tasks
-
I created a repository with SwiftUI examples for the Swift Algorithms package. Contribute an example to this project:
↗ SwiftAlgorithmsExamples: Examples for Swift Algorithms visualized in SwiftUI.
↗ How to contribute code to an iOS open source project -
The community-operated Swift Package Index also provides a package collection. Add it to the list of package collections in your Xcode and find a package that you're interested in and add it to the project:
↗ Swift Package Index -
Use the package collection generator for an package of your own choice and upload it to a public site (for example via GitHub Pages) and check if it can be used from Xcode:
↗ Creating a Swift Package Collection
↗ GitHub Pages
Discussion
More information
-
Package CollectionsBlog post announcing the Package Collections feature.
-
Announcing Swift AlgorithmsBlog post announcing the Swift Algorithms package