如何在应用程序项目中使用Cocoa Touch Frameworks [英] How to use Cocoa Touch Frameworks in an App Project

查看:174
本文介绍了如何在应用程序项目中使用Cocoa Touch Frameworks的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉构建单个iOS应用程序,但我坚持使用Cocoa Touch框架为多个应用程序共享公共代码。



问题:



框架的头文件不可见 /不能链接到使用的App项目。



我做了什么:



我创建了一个名为libTestFramework的项目Cocoa Touch Framework




  • 添加了一个类GoodMorning.h / m li>
  • 将类别从project更改为public

  • 成功创建项目并最终关闭



2。我创建了一个名为FrameworkTester的单视图应用程序




  • 然后将文件libTestFramework.xcodeproj从Finder拖到我的XCode项目我在目标FrameworkTester中的项目导航器(见下面的屏幕截图)中的根节点下直接添加了FrameworkTester。我在目标依赖关系下添加了libTestFramework,libTestFramework.framework链接二进制与库。



3。在App项目中:




  • 我试图从ViewController.h中的框架导入libTestFramework.h文件,找不到。



我误解了什么?



我创建了一个公开的github-Repository,其中包含要重现的两个项目:一个小鱼可能有你需要的。以下是您可以执行的错误列表


I am familiar building single iOS Apps, but i stuck on sharing common code to multiple apps with a Cocoa Touch Framework.

The Problem:

The Header-Files of the Framework are not visible/not linkable to the consuming App Project.

What i did:

1. I created a Project "Cocoa Touch Framework" called "libTestFramework"

  • added a Class "GoodMorning.h/m" with a method
  • changed the class from "project" to "public"
  • build the project successfully and finally closed it

2. I created a Single View Application called "FrameworkTester"

  • I then dragged the File "libTestFramework.xcodeproj" from the Finder into my XCode Project "FrameworkTester" directly under the root node in Project Navigator (see screenshot below)
  • in the target "FrameworkTester" I added the libTestFramework under "Target Dependencies" and the "libTestFramework.framework" under "Link Binary With Libraries" as well.

3. in the App Project:

  • I tried to import the "libTestFramework.h" File from the Framework in the ViewController.h, but it will not be found.

What did i misunderstood?

I created a public github-Repository containing both projects to reproduce: https://github.com/itinance/testCocoaTouchFramework

Some Screenshots following:

解决方案

I had the same problem. I don't know how to resolve your problem from your current situation but I do know how to do it from a new project. After following the steps below you could add your code until you get the working system you wanted. If you put the project into a git repository first, you could get it working and then do a diff to see what you were doing wrong. I'd be curious to see that too.

Wokring:

  1. Create a Single View Application called "FrameworkTester"
  2. Click File -> Add -> Target...
  3. Create "Cocoa Touch Framework" called "libTestFramework"
  4. Add required header and source to framework (start with something small)
  5. Add public headers to libTestFramework.h
  6. Go to configuration, select "libTestFramework" and Build Phases

    • Ensure your source is in Compile Sources
    • Ensure used headers are in Headers Public
  7. Put an obvious reference to the framework somewhere in "FrameworkTester"
  8. Run to test.

I'm writing this mostly from memory. If I've missed something then the article iOS 8 Extensions: Sharing Code with an Embedded Framework on A Tiny Fish will probably have what you need. And here are a list of mistakes you can make

这篇关于如何在应用程序项目中使用Cocoa Touch Frameworks的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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