1

Both projects use same frameworks. both have appdelegates. Successfully added both projects in workspace. but can not access each others controllers. making a static library of one project did not help. making a framework of one project?? which way to go?

Suraj
  • 71
  • 8

1 Answers1

3

Because you're talking about making a static library, I think your project is an OC project. So here's the thing, if you're going to merge these two apps , you should first take out the contents that can't be duplicated, like AppDelegate and some other app settings.

You said you put two projects into one workspace but you can't access to one project's view controllers from another. That's because you did not import the header in a right way.

For example, each project has its own header search path, which can be set at your xcodeproj-Build Settings->search header search path. By default, the current path(".") of one xcodeproj's header search path is at where your xcodeproj placed. And Xcode search all of the headers in that folder recursively.

If you want to access app B's header from app A. Assumed that you had a view controller in your app A's root folder. To Access app B's header, your import may seem like so:
#import "../app B/somekindofVC.h"
If you just want to import "somekindofVC.h", you can add "../app B" as a header search path in Build Settings, and select the 'recursive' option if necessary.

That's how your xcodeproj can find another's headers.

There is one more important thing should be done is that you should add app B's shared code into compile source. Since your app A could know a class of app B through header, the compiler doesn't know what is the implementation of app B's classes. So before you run your project, remember to add '.m' files you need in Build Phases->Compile Sources.

Turtleeeeee
  • 171
  • 7
  • #import "../Projectname" Did not work. am I missing anything? Is my folder structure wrong? – Suraj Aug 10 '17 at 13:44
  • If it did not work, you must be missing something. You'd better post your folder structure if you can, so I can go into more detail. And the folder structure doesn't mean Xcode's groups structure, it mean the REAL file organization that you can see it in your Finder. – Turtleeeeee Aug 11 '17 at 00:55
  • Btw, the header searching example I talked above is based on the condition that app A and app B is put in a big folder, so that each file of app A could use a relative path to find app B's header. – Turtleeeeee Aug 11 '17 at 01:02
  • ProjectMerge folder has ProjectA(folder), ProjectB(folder) and workspace file. ProjectA and B individually have their own .xcodeproject file and all other controllers , libraries and frameworks. – Suraj Aug 11 '17 at 08:51
  • Based on what you just said, that's hard to say what the problem is. I just created a [demo](https://github.com/dark19940411/MergeAppDemo) for you. You can check about it. It seems like Xcode project has to drag one file into its field when you add a file from outside after simply adding that file to its compile source. Btw, you can see `App A->ViewController.m`, it imports a header in App B. And you can run App A to see the result. – Turtleeeeee Aug 11 '17 at 15:56
  • How can we import whole Target instead of importing each and every controller? – Vinod Singh Oct 27 '17 at 10:16
  • @VinodSingh Dragging all of the files into your main project instead of dragging a whole target into your project may do the trick. In the end, we just want your files outside to be in the main target’s compile source. Otherwise, they won’t be compiled. – Turtleeeeee Oct 27 '17 at 10:57
  • @Turtleeeeee Actually I have to use whole application as module and according to your answer I have to import all controllers but I want to get rid of importing so many files. I want do it in a same manner we import a framework. Thanks – Vinod Singh Oct 27 '17 at 12:48
  • @VinodSingh As far as I've known, there is no such an easy way to import all of the logic modules of another project into your main project like making one drag. The best way I know is that you pick the code you need to use and drag them (like folder by folder if the imported project is well-organized ) to your main project. – Turtleeeeee Oct 29 '17 at 06:20