0
0
Swiftprogramming~30 mins

Project structure and Swift Package Manager basics - Mini Project: Build & Apply

Choose your learning style9 modes available
Project structure and Swift Package Manager basics
📖 Scenario: You are starting a new Swift project to manage a small library of books. You want to organize your code properly and use Swift Package Manager (SPM) to handle your project dependencies and build.
🎯 Goal: Build a simple Swift package with a basic project structure, add a configuration variable, write core logic to list book titles, and print the result.
📋 What You'll Learn
Create a Swift package with a Package.swift manifest file
Define a library target with source files
Add a configuration variable for minimum pages
Write core logic to filter books by page count
Print the filtered book titles
💡 Why This Matters
🌍 Real World
Organizing code and managing dependencies with Swift Package Manager is essential for building scalable and maintainable Swift applications.
💼 Career
Understanding project structure and package management is a key skill for Swift developers working on iOS, macOS, or server-side Swift projects.
Progress0 / 4 steps
1
Create the initial data structure
Create a Swift dictionary called books with these exact entries: "Swift Programming": 350, "iOS Development": 420, "Algorithms": 280, "Data Structures": 300 representing book titles and their page counts.
Swift
Need a hint?

Use a Swift dictionary with String keys and Int values.

2
Add a configuration variable
Add a constant called minPages and set it to 300 to use as a filter threshold for books.
Swift
Need a hint?

Use let minPages = 300 to create the constant.

3
Filter books by page count
Create a constant called filteredBooks that uses a dictionary comprehension to include only books with page counts greater than or equal to minPages.
Swift
Need a hint?

Use the filter method on the dictionary with a closure checking $0.value >= minPages.

4
Print the filtered book titles
Print the keys of filteredBooks as an array using print(Array(filteredBooks.keys)).
Swift
Need a hint?

Use print(Array(filteredBooks.keys)) to show the filtered book titles.