简体   繁体   English

带有可可豆荚的Swift框架

[英]Swift Framework with Cocoa Pods

I have created custom swift framework in this I have installed pods for using some third party framework. 我已经在其中创建了自定义的swift框架,并安装了用于使用某些第三方框架的pod。

I am done with the successful build now but How I can use or add that framework in my existing project. 现在我已经完成了成功的构建,但是如何在现有项目中使用或添加该框架。

Do I need to copy the entire framework project in my existing project? 我是否需要在现有项目中复制整个框架项目?

If any one knows the solution please help. 如果有人知道解决方案,请提供帮助。

Thank you. 谢谢。

The most obvious, easiest and manageable solution would be creating a pod . 最明显,最简单和可管理的解决方案是创建一个pod Then declare the required pods in xyz.podspec file to use your pod as dependencies. 然后在xyz.podspec文件中声明所需的Pod,以将Pod用作依赖项。

Use your custom cocoapod using following: 使用您的自定义cocoapod,方法如下:

pod 'Name', :path => '~/code/Pods/' # if in local file system
pod 'NAME', :git => 'https://example.com/URL/to/repo/NAME.git' # if it is in your private repo
  • Build your framework and copy from Product. 构建您的框架并从Product复制。 As shown in screenshot CyptoAPI.framework 如屏幕快照CyptoAPI.framework所示

在此处输入图片说明

  • Drag into you existing project and also add into Embedded Binaries. 拖到现有项目中,然后添加到“嵌入式二进制文件”中。

在此处输入图片说明

Hope this will help. 希望这会有所帮助。

  1. In your main project click with right click and select "Add files to yourProject.." 在您的主项目中,单击鼠标右键,然后选择“将文件添加到您的项目”。
  2. Then you add the file .xworkspace of your framework, so you can modify from there parts of code. 然后,添加框架的.xworkspace文件,以便可以从那里修改代码。
  3. After that go on the General page of Xcode, when you can select deployement Target, devices etc.. Go down until you see the section of Embedded Binaries , click on the button + and add the framework you added before with the command "Add files to yourProject.." in part 1 之后,在Xcode的“常规”页面上,可以选择部署目标,设备等。向下直到看到“ 嵌入式二进制文件 ”部分,单击按钮+并使用命令“添加文件”添加之前添加的框架。到yourProject ..”的第1部分中

I was also facing the same problem and here's what I did 我也面临着同样的问题,这就是我所做的

  1. Open the custom framework you are creating, under products section in the navigation bar right click on the your custom framework (eg customFramework.framework) file and select "reveal in finder". 打开要创建的自定义框架,在导航栏中的产品部分下,右键单击您的自定义框架(例如customFramework.framework)文件,然后选择“在finder中显示”。

  2. Now along with your custom framework you can see all the third party frameworks you are using. 现在,连同您的自定义框架,您可以看到您正在使用的所有第三方框架。 Copy all the frameworks you need and paste them wherever you feel like so you can easily access to them. 复制所需的所有框架,然后将其粘贴到所需的任何位置,以便可以轻松访问它们。

  3. Now open up your existing project where you want to use your custom framework. 现在打开您要使用自定义框架的现有项目。

  4. Go to Embedded Binaries section in the general tab of your target. 转到目标常规选项卡中的“嵌入式二进制文件”部分。 Click on the + button -> click on add other -> navigate to location where you pasted all your required frameworks along with your custom framework and click open. 单击+按钮->单击添加其他->导航到将所有必需框架以及自定义框架粘贴到的位置,然后单击打开。

That's it. 而已。 Do this and let me know if it helped you. 这样做,让我知道它是否对您有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM