如何手动将第三方Swift框架导入Swift iOS项目?

时间:2023-02-05 11:31:42

I am trying to import and use the OAuthSwift library in the Swift iOS project. I followed their directions:

我正在尝试导入并使用Swift iOS项目中的OAuthSwift库。我按照他们的指示:

  • Drag OAuthSwift.xcodeproj to your project in the Project Navigator.
  • 在项目导航器中将OAuthSwift.xcodeproj拖到项目中。
  • Select your project and then your app target. Open the Build Phases panel.
  • 选择您的项目,然后选择您的应用目标。打开Build Phases面板。
  • Expand the Target Dependencies group, and add OAuthSwift framework. import OAuthSwift whenever you want to use OAuthSwift.
  • 展开Target Dependencies组,然后添加OAuthSwift框架。每当要使用OAuthSwift时,都要导入OAuthSwift。

After completing these steps, importing OAuthSwift using import OAuthSwift causes the error No such module 'OAuthSwift' and the project fails to build.

完成这些步骤后,使用导入OAuthSwift导入OAuthSwift会导致错误没有此类模块“OAuthSwift”并且项目无法构建。

I have tried the following steps, based on a number of other SO questions about similar issues:

基于类似问题的其他一些SO问题,我尝试了以下步骤:

  • Clean and rebuild
  • 清洁和重建
  • Add the OAuthSwift framework to many different combinations of Build Phases > Target Dependencies, Build Phases > Link Binary With Libraries, Build Phases > Embed Frameworks, and General > Embedded Libraries
  • 将OAuthSwift框架添加到构建阶段>目标依赖关系,构建阶段>链接二进制库,构建阶段>嵌入框架和常规>嵌入式库的许多不同组合中
  • Set Build Settings > Search Paths > Framework Search Paths and Build Settings > Search Paths > Library Search Paths to $(SRCROOT) and recursive.
  • 将构建设置>搜索路径>框架搜索路径和构建设置>搜索路径>库搜索路径设置为$(SRCROOT)并递归。
  • Verify that my deployment target matches the deployment target of the OAuthSwift Xcode project.
  • 验证我的部署目标是否与OAuthSwift Xcode项目的部署目标匹配。

I have tested this using the latest version of OAuthSwift from their master branch using a git submodule, as well as manually downloading and importing each of the two latest tagged versions (0.6.0 and 0.5.2).

我使用git子模块从他们的主分支使用最新版本的OAuthSwift测试了这个,以及手动下载和导入两个最新的标记版本(0.6.0和0.5.2)。

I have also created a brand new Xcode project, imported OAuthSwift as above, and encountered the same error.

我还创建了一个全新的Xcode项目,如上导入OAuthSwift,并遇到了同样的错误。

Finally, I also tried importing a different Swift Framework (Alamofire), following the steps as stated on the README at https://github.com/Alamofire/Alamofire. This caused the same error as well: No such module 'Alamofire'.

最后,我还尝试按照https://github.com/Alamofire/Alamofire上的README中所述的步骤导入不同的Swift框架(Alamofire)。这也导致了同样的错误:没有这样的模块'Alamofire'。

I am using:

我在用:

  • OSX 10.11.6
  • OSX 10.11.6
  • Xcode 7.3.1
  • Xcode 7.3.1
  • Swift 2.2
  • 斯威夫特2.2

I'm still fairly new to Xcode and the Swift module system, so any help or suggestions is appreciated.

我仍然是Xcode和Swift模块系统的新手,所以任何帮助或建议都值得赞赏。

1 个解决方案

#1


2  

Your life will be a lot easier if you import the framework using CocoaPods. If you haven't used them before, it's really easy once you get set-up. You use Ruby Gems on the command line to install CocoaPods (sudo gem install cocoapods) and then create a create a pod file using pod init. After this you modify it to include:

如果使用CocoaPods导入框架,您的生活将变得更加容易。如果您之前没有使用它们,那么一旦您进行了设置,这将非常简单。您可以在命令行上使用Ruby Gems来安装CocoaPods(sudo gem install cocoapods),然后使用pod init创建一个创建pod文件。在此之后,您将其修改为包括:

platform :ios, '8.0'

use_frameworks!

pod 'OAuthSwift', '~> 0.5.0'

Save the file and run pod install.

保存文件并运行pod install。

Once this is complete you will have to close out the Xcode project and use the newly created .xcworkspace project file (not the .xcodeproj) from here forward.

完成后,您将不得不关闭Xcode项目并从此处使用新创建的.xcworkspace项目文件(而不是.xcodeproj)。

Here is a link to another post for a secondary reference. How to install cocoapods?

以下是指向辅助参考的其他帖子的链接。如何安装cocoapods?

#1


2  

Your life will be a lot easier if you import the framework using CocoaPods. If you haven't used them before, it's really easy once you get set-up. You use Ruby Gems on the command line to install CocoaPods (sudo gem install cocoapods) and then create a create a pod file using pod init. After this you modify it to include:

如果使用CocoaPods导入框架,您的生活将变得更加容易。如果您之前没有使用它们,那么一旦您进行了设置,这将非常简单。您可以在命令行上使用Ruby Gems来安装CocoaPods(sudo gem install cocoapods),然后使用pod init创建一个创建pod文件。在此之后,您将其修改为包括:

platform :ios, '8.0'

use_frameworks!

pod 'OAuthSwift', '~> 0.5.0'

Save the file and run pod install.

保存文件并运行pod install。

Once this is complete you will have to close out the Xcode project and use the newly created .xcworkspace project file (not the .xcodeproj) from here forward.

完成后,您将不得不关闭Xcode项目并从此处使用新创建的.xcworkspace项目文件(而不是.xcodeproj)。

Here is a link to another post for a secondary reference. How to install cocoapods?

以下是指向辅助参考的其他帖子的链接。如何安装cocoapods?