在现有的xcode项目上使用swift包管理器

时间:2023-01-24 07:25:24

im new to the swift and xcode world, so i'm having a problem trying to integrate a package to my project.

我是swift和xcode世界的新手,所以我在尝试将软件包集成到我的项目时遇到了问题。

I want to add Alamofire dependency, with the following commands:

我想使用以下命令添加Alamofire依赖项:

Inside my root project folder:

在我的根项目文件夹中:

swift init

this creates the Package.swift file, i add the dependency inside, run then:

这会创建Package.swift文件,我在里面添加依赖项,然后运行:

swift build

Everything seems to be ok, but im my project when i try to import my library:

一切似乎都没问题,但是当我尝试导入我的库时,我的项目是:

import Alamofire

I get an error, it says that the module is not recognized. So my question here is, what is the correct steps to integrate Package Manager and a dependency on a existing project without crashing everything.

我收到错误,它说模块无法识别。所以我的问题是,在没有崩溃的情况下,将Package Manager和依赖项集成到现有项目的正确步骤是什么。

UPDATE:

更新:

swift build

outputs:

输出:

Resolved version: 4.3.0
Compile Swift Module 'Alamofire' (17 sources)
Compile Swift Module 'Sample' (1 sources)

And my Package.swift is:

我的Package.swift是:

import PackageDescription

let package = Package(
    name: "Sample",
    dependencies: [
        .Package(url: "https://github.com/Alamofire/Alamofire.git", majorVersion: 4)
    ]
)

1 个解决方案

#1


0  

Swift Package Manager is a standalone tool which allows managing dependencies and building projects without Xcode. It can generate Xcode projects for you with swift package generate-xcodeproj.

Swift Package Manager是一个独立的工具,它允许在没有Xcode的情况下管理依赖项和构建项目。它可以使用swift包generate-xcodeproj为您生成Xcode项目。

However, at the moment, Swift Package Manager only has support for building projects for macOS and Linux platforms. The only way to build projects for iOS, tvOS and watchOS is using Xcode, which includes the SDKs needed for these platforms.

但是,目前,Swift Package Manager仅支持为macOS和Linux平台构建项目。为iOS,tvOS和watchOS构建项目的唯一方法是使用Xcode,其中包括这些平台所需的SDK。

There are ways to use Swift Packages Manager to manage dependencies for iOS/tvOS/watchOS, but it is not easy and requires manual work. If you are interested, take a look at https://github.com/j-channings/swift-package-manager-ios

有一些方法可以使用Swift Packages Manager来管理iOS / tvOS / watchOS的依赖关系,但这并不容易,需要手动工作。如果您有兴趣,请查看https://github.com/j-channings/swift-package-manager-ios

Other than that, I'd recommend using Carthage or CocoaPods.

除此之外,我建议使用Carthage或CocoaPods。

#1


0  

Swift Package Manager is a standalone tool which allows managing dependencies and building projects without Xcode. It can generate Xcode projects for you with swift package generate-xcodeproj.

Swift Package Manager是一个独立的工具,它允许在没有Xcode的情况下管理依赖项和构建项目。它可以使用swift包generate-xcodeproj为您生成Xcode项目。

However, at the moment, Swift Package Manager only has support for building projects for macOS and Linux platforms. The only way to build projects for iOS, tvOS and watchOS is using Xcode, which includes the SDKs needed for these platforms.

但是,目前,Swift Package Manager仅支持为macOS和Linux平台构建项目。为iOS,tvOS和watchOS构建项目的唯一方法是使用Xcode,其中包括这些平台所需的SDK。

There are ways to use Swift Packages Manager to manage dependencies for iOS/tvOS/watchOS, but it is not easy and requires manual work. If you are interested, take a look at https://github.com/j-channings/swift-package-manager-ios

有一些方法可以使用Swift Packages Manager来管理iOS / tvOS / watchOS的依赖关系,但这并不容易,需要手动工作。如果您有兴趣,请查看https://github.com/j-channings/swift-package-manager-ios

Other than that, I'd recommend using Carthage or CocoaPods.

除此之外,我建议使用Carthage或CocoaPods。