将框架和App Extension目标添加到IOS App项目中,我做得正确吗? [英] Adding Framework and App Extension targets to IOS App project, am I doing it correctly?

查看:111
本文介绍了将框架和App Extension目标添加到IOS App项目中,我做得正确吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究IOS / Swift开发,并希望构建一个IOS应用程序,该应用程序将来将具有自己的Today Extension。我已经读到最好将App及其扩展之间的通用逻辑(例如访问Internet资源,对结果执行某些工作的逻辑等)放入自定义框架中。因为我认为我需要在App开发期间更改Framework和App代码,我想避免在单独的项目中构建框架,而不是使用Show In Finder函数定位框架包,然后将其拖放到App中因此,我想知道这是否是使用应用程序,其使用的框架以及应用程序的今日扩展建立工作区的正确方法:

I'm studying IOS/Swift development and I'd like to build an IOS app that in the future will have its own Today Extension. I've read that it is better to put the common logic (for example the logic that accesses Internet resources, performs some job on the result etc) between the App and its extension into a Custom Framework.. Since I think I'll need to change both Framework and App code during the development of the App, I'd like to avoid building the framework in a separate project, than use Show In Finder function to locate the framework bundle and then drag-and-dropping it within the App project.. So I'd like to know if this is the correct way to set up a Workspace with an App, the framework it uses and the Today Extension of the App:


  1. 使用IOS应用程序目标创建新项目

  2. 在项目浏览器中选择项目然后 Editor-> Add Target ... 并指定 Cocoa Touch Framework

  3. Editor-> Add Target。 .. 并指定今日扩展

  4. 在链接框架中添加框架nd库

  1. Create a new Project with an IOS App target
  2. Select the project in the Project Navigator and then Editor->Add Target... and specify a Cocoa Touch Framework
  3. Editor->Add Target... and specify Today Extension
  4. Add the framework in Linked Frameworks and Libraries

通过这种方式,我已经看到对框架源的更改不需要重新编译框架目标,也许是因为即使我仅构建&,该项目也知道需要重新编译框架源代码。运行使用该框架的IOS App目标?我做对了吗?我已经看到,以这种方式创建的Today Extension在IOS App的过程中并未在 Build Phases-> Target Dependencies 中列出该框架,但它们都正确使用了框架的更新代码当我更新它时。

In this way I've seen that changes to the Framework sources do not need a Framework target recompilation, maybe because the project knows about the need to recompile framework sources even if I only build & run the IOS App target that uses that framework? Am I doing it right? I've seen that the Today Extension created in such way does not lists the framework in the Build Phases -> Target Dependencies while the IOS App does, but both of them correctly use the updated code of the Framework when I update it.

然后,我在编译项目时注意到以下警告,但是我不知道它是否与我的方式有关ve设置了项目:

Then, I've noticed the following warning when I compile the project, but I don't know if it is related to the way I've setup the project:

ld: warning: linking against dylib not safe for use in application extensions: /Users/gianni/Library/Developer/Xcode/DerivedData/TestFrameworkApp-dshihhfiuepeqzddbnpgnfwilhem/Build/Products/Debug-iphonesimulator/TestFramework.framework/TestFramework

顺便说一句, Products 文件夹中的条目始终为红色是否正常?是否由于我没有用于开发IOS设备的付费开发者帐户而只为IOS Simulator进行构建的事实?这是否阻止我构建可以导出到其他项目的框架,因为我无法通过右键单击框架产品并选择在Finder中显示来找到框架包(因此,我可以

BTW is it normal that the entries within the Products folder are always red? Is it due to the fact that I build only for IOS Simulator since I don't have a Paid developer account that allows me to build for an IOS Device? Does this prevent me to build a framework that can be exported for some other Project since I can't find the Framework bundle with a right clicking on the framework product and selecting Show In Finder (and so I can't drag-and-drop it to another project)?

我希望我已经足够清楚了,您会为我指明正确的方向,以了解什么是开始我的新项目的建议方法:)

I hope I've been clear enough and that you'll point me in the right direction to understand what is the suggested way of starting my new project :)

推荐答案

在我看来,您正沿着正确的道路前进将采取。

It sounds to me like you're headed down the exact path I would take.

关于您看到的警告...我相信检查共享框架的仅允许应用程序扩展API会抑制这种情况,并在您创建时导致构建失败尝试使用扩展中不允许的API。

Regarding the warning you're seeing... I believe that checking the "Allow app extension API only" for your shared framework will supress that and cause build failures when you attempt to use a API that is not allowed in extensions.

这篇关于将框架和App Extension目标添加到IOS App项目中,我做得正确吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆