本文介绍了在子项目(框架项目)中使用第三方窗格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用XCode 8 + Swift 3。

I am using XCode 8 + Swift 3.

我创建了一个新的iOS项目,名为 MyApp

I created a fresh iOS project named "MyApp".

然后,我创建了一个名为 MySubProject的可可触摸框架项目。
(想法是让 MyApp 项目访问 MySubProject 代码。)

Then, I create a Cocoa touch framework project, named "MySubProject".(The idea is to have MyApp project accessing MySubProject code.)

它们位于相同级别的文件夹:

They are on the same level folder:

- MyApp/
- MySubProject/

我将 MySubProject 添加到 MyApp 项目中,链接了 MySubProject 框架。一切正常。我的项目结构如下:

I added MySubProject into MyApp project, linked the MySubProject framework. Everything works fine. My project structure looks like this:

全部一直工作到这里! (MyApp代码可以访问MyService代码)

All works until here! (MyApp code can access MyService code)

现在,我需要 MySubProject 才能使用Alamofire与后端进行通信。因此,在 MySubProject / 下,我用CocoaPod设置了Alamofire,它创建了 MySubProject.xcworkspace

Now, I need MySubProject to use Alamofire to communicate with backend. So, under MySubProject/ I setup the Alamofire with CocoaPod, which creates the MySubProject.xcworkspace.

我想我需要删除以前的 MySubProject.xcodeproj 并使用 MySubProject.xcworkspace ,因此我删除了 MySubProject.xcodeproj &将 MySubProject.xcworkspace 添加到 MyApp ,它看起来像这样:

I think I need to remove the previous MySubProject.xcodeproj and using MySubProject.xcworkspace, so I deleted the reference of MySubProject.xcodeproj& add the MySubProject.xcworkspace to MyApp, it then looks like this:

如您所见,我看不到 MySubProject

As you can see, I can not see the source code of MySubProject now.

通过Framework子项目中的CocoaPod使用Alamofire或任何第三方库的正确方法是什么?

What is the correct way to use Alamofire or any 3rd party library through CocoaPod in Framework sub-project?

=====更新======
我需要将Alamofire添加到 MySubProject ,而不是 MyApp 。我按照Alamofire官方网站上的说明将Alamofire手动添加到 MySubProject 中,项目结构如下所示:

===== UPDATE ======I need to add Alamofire into MySubProject, not MyApp. I followed instruction in Alamofire offical website to manually add Alamofire to MySubProject, the project structure then looks like this:

- MyApp
  - MySubProject.xcodeproj
    -Alamofire.xcodeproj

之后,我可以在MySubProject中访问Alamofire,没有编译错误。但是,当我在模拟器中运行应用程序时,出现运行时错误:

After that, I can access Alamofire in MySubProject, no compile error. However, when I run my app in emulator, I got runtime error:

Referenced from: /Users/myname/Library/Developer/Xcode/DerivedData/MyApp-hezjlyvzxnavccenabxdepgftbrg/Build/Products/Debug-iphonesimulator/Alamofire.framework/Alamofire
  Reason: image not found

如何解决?

推荐答案

3) When using custom pods you can provide a dependency in the .podspec file. Via this method I can import my own library (as a pods) which depends on other Cocoapods.

编辑:经过一番仔细的考察,我们得出了结论上面的方法不符合leem.fin的特定要求。不可能将一个框架包含在另一个框架中。但是还有其他两种选择:

After a good look we came to the conclusion that the methods above didn't met leem.fin's specific requirements. It's NOT possible to include a framework into another framework. But there're two other options:

1)除了框架之外,还交付辅助框架并将其链接到您自己的框架。这样,MySubProject和MyApp都可以链接到该框架。

1) Ship the secondary framework besides your framework and link it to your own framework. This way both MySubProject and MyApp can link to that framework.

2)将源直接导入MySubProject,以便将它们与MySubProject.framework一起编译。

2) Import the sources directly into MySubProject so they'll be compiled with the MySubProject.framework and they're accessible for other targets that simply link to MySubProject.

最简单的方法是将源直接导入MySubProject。如果您不复制资源而是链接到文件夹,则可以在需要获取最新更改时git更新源。

The easiest way is importing the sources directly into the MySubProject. If you don't copy the resources but link to the folder, you can git update the sources when you need to to get the latest changes.

这篇关于在子项目(框架项目)中使用第三方窗格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-15 13:18