I am trying to create a new swift package i did the following commands on console
swift package init
swift package generate-xcodeproj
This works and generates an empty project. Inside the project sample file i added just one line
Import UIKit
In Xcode, this builds correctly.
But on console, when I do swift build
command,
I get this error
/Users/home/Desktop/TT/Sources/TT/TT.swift:1:8: error: no such module 'UIKit'
import UIKit
Is there any thing I am doing wrong?
You should select an iOS based target to make it available:
If you leave it selecting macOS (by default), you will get the error.
if you want your package to be available only for specific platforms (for example only for iOS), you should specify the platform in the package.swift
file:
let package = Package(
name: "MyLibrary",
platforms: [
.iOS(.v9)
],
products: [
,,,
If you need your framework to be available on multiple platforms, don't forget to check the availability of the imported framework like:
#if canImport(UIKit)
import UIKit
// And do the rest of UIKit dependent code
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With