Skip to content
tezvyn:

Package.swift manifest: library vs executable products

Source: interviewEasyHow cards are made

Summary

understanding SPM package structure.

Key points

the manifest declares name, targets, dependencies, and products; a library is consumed by other code while an executable produces a runnable binary with an entry point.

What's really being asked

The interviewer checks foundational SPM literacy: that the manifest is the source of truth for a package and that products are the externally visible deliverables built from internal targets.

The full answer

Package.swift is the manifest, executable Swift code beginning with a tools-version comment and importing PackageDescription. It declares the package name, the supported platforms and minimum OS versions, the external package dependencies, the targets which are the units of compiled code with their source paths and per-target dependencies, and the products which are what consumers actually depend on. A .library product groups one or more targets to be imported and linked by other packages or applications; it has no entry point and cannot run by itself. An .executable product builds a runnable binary and is backed by a target that contains a main entry point, suitable for command-line tools.

The mistakes people make

Using targets and products interchangeably; products are the public surface, targets are the build units behind them. Believing a library is independently runnable. Forgetting that the tools-version line determines which Swift features the manifest may use.

What usually comes next

What is the difference between a target and a product? When would you mark a library as static versus dynamic? How do test targets fit into the manifest?

A concrete example

A package defines two targets, NetworkingCore with the implementation and a small CLI target with an entry point that calls into it. The manifest vends two products: .library(name: "Networking", targets: ["NetworkingCore"]) which apps import, and .executable(name: "netcli", targets: ["CLI"]) which builds a runnable tool. An app depending on the package imports the Networking library product, while a developer can run the netcli executable from the command line. The library cannot launch on its own because it has no main entry point.

Interview question

What distinguishes a .executable product from a .library product in Package.swift?

  • a.An executable can be imported by apps; a library cannot
  • b.A library compiles faster because it skips optimization
  • c.Only executables may declare external dependencies
  • d.An executable builds a runnable binary with an entry point; a library is linked into other codeCorrect
Why?

An executable product produces a runnable binary backed by an entry point, while a library is meant to be imported and linked by other code and cannot run alone. Both may have dependencies, and the import relationship is the reverse of the first option.

Just read this? Test yourself on what you have been reading.

Read the original → developer.apple.com

Put your scrolling time to good use

Learn one idea, try a quiz and save useful cards for revision. Tezvyn makes it easy to learn and stay current in your tech field, a few minutes at a time.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on ios — each one lists the topics its interview covers.

See open roles