Adding a Swift Package dependency in Xcode
basic SPM workflow knowledge.
add via File menu, paste the repo URL, choose a version rule like up-to-next-major, link the product to your target.
WHAT THIS TESTS This is a baseline competency check: can you add a dependency the modern Apple-native way and reason about version pinning so builds stay reproducible.
A GOOD ANSWER COVERS In Xcode you open the File menu and choose Add Package Dependencies, or select the project, the Package Dependencies tab, and the plus button. You paste the package's Git URL into the search field. Xcode fetches the package and presents a Dependency Rule: Up to Next Major Version is the common default, but you can choose Up to Next Minor, an Exact Version, a Version Range, a specific commit, or a branch. After resolving, Xcode asks which product or products from the package to add and to which target, which is what actually links the library. Xcode writes the resolved versions into Package.resolved so teammates and CI get identical versions.
COMMON WRONG ANSWERS Describing pod install and a Podfile, which is CocoaPods, not SPM. Forgetting the final step of attaching the product to a target, leaving the import unavailable. Always tracking a branch, which makes builds nondeterministic, when a semantic version range is the safer default.
LIKELY FOLLOW-UPS What does Package.resolved do and should you commit it? What is the difference between Up to Next Major and Exact? How do you update a package to a newer version later?
ONE CONCRETE EXAMPLE To add a networking library you choose File then Add Package Dependencies, paste its GitHub URL, select Up to Next Major Version starting at 5.0.0 so you accept 5.x but not a breaking 6.0, click Add Package, then tick its single library product and assign it to the app target. You commit the updated project file and Package.resolved so every build, local or CI, resolves the same revision until you deliberately update.
Read the original → developer.apple.com
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.