# SwiftPM "swift build" for iOS

**URL:** <https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517>\
**Category:** Using Swift\
**Tags:** packagemanager, command-line-tool\
**Created:** [December 4, 2020, 4:52pm UTC](https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517 "2020-12-04T16:52:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![scannillo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scannillo/32/13463_2.png) [@scannillo](https://forums.swift.org/u/scannillo)\
**Post date:** [December 4, 2020, 4:53pm UTC](https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517/1 "2020-12-04T16:53:00Z")

</div>

Hello

I am developing a Swift Package for iOS. In using attempting to use the command line tool `swift build`, it will result in `fatal error: 'UIKit/UIKit.h' file not found`. I know my package is working properly, since I can import it via iOS apps.

It seems that `swift build` is only configured to build for MacOS, and I don't see any options via `swift build --help` to allow specifying the OS. Is there something I am missing, or is this a feature that is being developed? It would definitely speed up and improve the dev process for building Swift Packages.

Thank you for your help!

[See similar issue on Stack Overflow.](https://stackoverflow.com/questions/62416880/how-do-you-build-ios-specific-packages-using-spm)

---

<div class="post-metadata">

**Author:** ![NeoNacho](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/neonacho/32/1368_2.png) [@NeoNacho](https://forums.swift.org/u/NeoNacho)\
**Post date:** [December 4, 2020, 6:22pm UTC](https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517/2 "2020-12-04T18:22:47Z")

</div>

You're not missing anything, `swift build` indeed does not support iOS. You can build your package on the commandline using `xcodebuild`, though.

You can use `xcodebuild -list` to see the available schemes and then use `xcodebuild` just like you would with an Xcode project, including passing `-destination` to build for iOS.

---

<div class="post-metadata">

**Author:** ![scannillo](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/scannillo/32/13463_2.png) [@scannillo](https://forums.swift.org/u/scannillo)\
**Post date:** [December 29, 2020, 11:00pm UTC](https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517/3 "2020-12-29T23:00:57Z")

</div>

Hi @NeoNacho, thanks for the reply.

I know that `xcodebuild` can be used to build schemes. Though, I am curious if there is a way a command line tool to verify that a Swift Package can be built to be consumed (similar to `pod lib lint` available in CocoaPods - which spins up a sample xcodeproj and makes sure the Pod you're developing is able to be consumed).

I don't see any similar offerings via the `swift package` command line tools. I wanted to ask as it would make developing and testing a Swift Package quicker and more efficient. Thanks!

Thanks!

---

<div class="post-metadata">

**Author:** ![jazz](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/jazz/32/19389_2.png) [@jazz](https://forums.swift.org/u/jazz)\
**Post date:** [January 21, 2022, 10:41am UTC](https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517/4 "2022-01-21T10:41:39Z")

</div>

I was able to get this working for swift-only packages with the below command, However Objc files still fail.

```swift
swift build -Xswiftc "-sdk" -Xswiftc "`xcrun --sdk iphonesimulator --show-sdk-path`" -Xswiftc "-target" -Xswiftc "x86_64-apple-ios13.0-simulator"

```

---

<div class="post-metadata">

**Author:** ![markturnip](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/markturnip/32/23088_2.png) [@markturnip](https://forums.swift.org/u/markturnip)\
**Post date:** [June 21, 2024, 6:24am UTC](https://forums.swift.org/t/swiftpm-swift-build-for-ios/42517/5 "2024-06-21T06:24:33Z")

</div>

still seems to be building for macos despite passing iOS target:

```swift
error: the library 'xxx' requires macos 10.13

```

I could wrap everything is directives to get it to build, but then binary won't include any of my iOS definitions!

```swift
#if os(iOS)
@objc public class MediaPlayer : NSObject {

```

Alternative is to build using `xcodebuild`

```swift
xcodebuild build -scheme RadioPlayerLocal -sdk "`xcrun --sdk iphonesimulator --show-sdk-path`" -destination "OS=17.1,name=iPhone 13 Pro"  

```
