# Swift Package top level file

**URL:** <https://forums.swift.org/t/swift-package-top-level-file/87065>\
**Category:** Using Swift\
**Tags:** swift-package\
**Created:** [June 3, 2026, 4:37am UTC](https://forums.swift.org/t/swift-package-top-level-file/87065 "2026-06-03T04:37:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [June 3, 2026, 4:37am UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/1 "2026-06-03T04:37:51Z")

</div>

Hi,

## Overview

I have a swift package called `Vehicles`

This contains the following files / types:

- `Car.swift`
- `Bus.swift`
- `Truck.swift`

## Doubt

There is a file called `Vehicles.swift` created, I am not sure what to write there.  
If I delete the file it throws the compilation error.

## Questions

1. What should I do in `Vehicles.swift`? (I don't have any type called Vehicles to define there)
2. Is it ok to leave it blank?
3. What is the normal practice in such cases?

Thanks

---

<div class="post-metadata">

**Author:** ![Diggory](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/diggory/32/4320_2.png) [@Diggory](https://forums.swift.org/u/Diggory)\
**Post date:** [June 3, 2026, 7:12am UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/2 "2026-06-03T07:12:59Z")

</div>

You will find the [SwiftPM documentation](https://docs.swift.org/swiftpm/documentation/packagemanagerdocs) very useful.

However, to directly answer your question:

Packages have a _manifest_ file (`Package.swift`) at the top of the package. This file lists what _Products_ the package offers to other Swift code. If you made the package in the default way (either via the `New > Package…` menu item in Xcode, or via `swift package init` in the terminal then your package will have a predefined single _Library_ product whose name matches the name of the Package (in your case `Vehicles`.) In order to build that product, SwiftPM has a build _target_ (also named `Vehicles`.)

So, your package already offers a Swift Library named `Vehicles` and that library is built by SwiftPM using the `Vehicles.swift` source file. Thus removing that file causes an error.

I would say that it's fine to leave `Vehicles.swift` empty and define all your library's types in other source files in the `/Sources/Vehicles/` folder (source files in this folder will be compiled into the `Vehicles` Library module.) How you organise the source code in this folder is up to you.

---

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [June 3, 2026, 8:28am UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/3 "2026-06-03T08:28:54Z")

</div>

@Diggory Thank you so much for that clear explanation.

I will also go through the SwiftPM documentation.

---

<div class="post-metadata">

**Author:** ![ole](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ole/32/18720_2.png) [@ole](https://forums.swift.org/u/ole)\
**Post date:** [June 3, 2026, 12:29pm UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/4 "2026-06-03T12:29:17Z")

</div>

Just to be clear, SwiftPM definitely _does not_ require to have a source file with the same basename as the target/directory name.

If you don’t want/need the file `Vehicles.swift`, it's absolutely fine to delete it.

The only requirement is that every target (except system or executable targets, I believe) must have _at least one_ source file. So you will get an error if you create a new package and then delete the lone `Vehicle.swift` from the `Vehicles` target. But that error will go away as soon as you create one or more other `.swift` files in that directory, as it seems you have done @somu. (Note that SwiftPM expects the source files to be in the target's directory, e.g. under `Sources/Vehicles`. It's not clear from your original post if you have put them there.)

@somu Please provide more information about your package so we can help you:

- What's the full directory structure of your package?
- What compilation error (exact error message) are you seeing?

---

<div class="post-metadata">

**Author:** ![Diggory](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/diggory/32/4320_2.png) [@Diggory](https://forums.swift.org/u/Diggory)\
**Post date:** [June 3, 2026, 1:07pm UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/5 "2026-06-03T13:07:42Z")

</div>

Oops, you are right. Sorry about that.

---

<div class="post-metadata">

**Author:** ![somu](https://avatars.discourse-cdn.com/v4/letter/s/ce73a5/32.png) [@somu](https://forums.swift.org/u/somu)\
**Post date:** [June 3, 2026, 1:07pm UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/6 "2026-06-03T13:07:44Z")

</div>

Thanks a lot @ole!!

You are right, it compiles just fine as long as there are other swift files.

I am so sorry for the confusion.

---

<div class="post-metadata">

**Author:** ![ole](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ole/32/18720_2.png) [@ole](https://forums.swift.org/u/ole)\
**Post date:** [June 3, 2026, 1:49pm UTC](https://forums.swift.org/t/swift-package-top-level-file/87065/7 "2026-06-03T13:49:47Z")

</div>

No problem! I'm glad it's now working for you.
