2

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:

enter image description here

enter image description here

enter image description here

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your helpfull advice. It works perfectly with a single application project having multiple targets for multiple purposes. But it doesn't solve to reuse this framework over multiple projects where all are put together in a workspace
Exactly. Put the project in version control. Setup the project as I've said above. Diff the project. Then you'll see what settings need adjusting for your other projects. If you write what you find here then you'll also help anyone googling to find an answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.