two projects in xcode4 workspaces (#import failure) - import

I'm really struggling to get this to work in xcode 4.
I have one project that I will reuse in many applications (networking) so I create a workspace and add my two projects. So far so good....
This is where it fails..
#import "JSONRequest.h"
For no apparent reason. It auto completes the file name of the header file. I thought this had something to do with the "scheme" (also new in xcode 4) so I've tried to add my networking target in the build phase. Changing order of them... set "Shared" under Manage schemes.. I've tried so many different combinations of the settings without any success.. And the error message is get is:
JSONRequest.h: No such file or directory
If you have a clue, please let me know.

You can add the header or source folder of your project you're referencing to your Header Search Paths.
Click on the target that's importing JSONRequest.h.
Click on Build Settings.
Enter "Header Search Paths" into the search box.
Double click on the value cell.
Click the + sign.
Set the path to the project you're referring. Let's say it's called JSONlib. The path is relative to the root of the referring project (the project that's using JSONlib). For example: ../JSONlib/src/headers/ or wherever it is that the .h file lives.
Click done.
Clean and then build.
You'll find more info about this problem in the apple developer forums. Best of luck.

What are you really trying to do?
If you have an entire Xcode project you intend to share between different products that usually suggests your project builds one or more targets (such as a framework, etc.). Therefore, your "shared" project should be able to build the framework on its own, irrespective of the workspace it's contained in, right?
Let's assume it's a framework. In most cases, Xcode can figure out the dependency by simply adding the framework product to the Link build phase of the (assumed) app using the framework. Done. Xcode should know to build the framework project's target first, since it's linked against when building the app project's target.
So your problem is likely just a matter of knowing where Xcode is looking to find files. Since projects within workspaces share that workspace's build folder, they can all "see" each other. But in the case of a framework, A simple import by file name won't cut it. You'd need:
#import <MyNetworkingFramework/MyNetworkingFramework.h>
Since you're including a specific header (JSONRequest.h) (which must be one of the public headers in the framework target's copy headers build phase), you'd need:
#import <MyNetworkingFramework/JSONRequest.h>
If your "shared" project is not a framework, you'll need to amend your question to include a more thorough description of your two projects and their targets.

This worked for me,
In build settings --> Header Search Path --> Add below entry
$(SRCROOT) and mark it as recursive. If above not worked you can also try following way, <path-of-other-project> and mark it as recursive. Hope this helps to you ! (You may require to clean or restart the workspace)

Related

Three20/Three20.h file not found for Archive

I'm trying to update an app that already have the Three20 library. Now i'm using xcode 4.5 and everytime i try to make an Archive i recive this error:
Three20/Three20.h file not found
At the beginning i wasn't able to make any kind of build,but after the adding of $(BUILT_PRODUCTS_DIR)/../three20 and $(BUILT_PRODUCTS_DIR)/../../three20 in the Header Search Path of the build and the target settings i can make a Build in my Device. Anyway if i try to made an Archive to publish my app, the same errors returns. What i can do? I have already reinstall the last version of Three20.... I have to try this solution that i found on internet:
Go to Xcode4 Preferences (Cmd + ,) > Locations > Build Location > and select “Place build products in locations specified by targets”
In xcode 4.5 i can't approach this solution...Maybe Build Location menù is changed, i can't find the option “Place build products in locations specified by targets” .... Someone knows where i can found this setting?
At least there's someone how have made successfully an Archive on Xcode4.5 and Three20?
I also support switching away from three20, but sometimes it's not that simple.
To resolve your issues, you can try to use CocoaPods. it's a library dependencies tool that let's you add any library you need. someone added a pod for three20 few weeks ago.
That should let you build your project using the standard xcode archive process.
If you don't feel like using cocoapods, you can also build that app using the "Build for..." -> "Archiving". you can find it in the same "Product" menu. it will generate a .app file that you can submit using the Application Loader app.
you can find the .app file by secondary clicking on the target name under the "Products" folder in your project sidebar.
I did the following to make it work for me:
for the three20 static library, I used cocoapods to include the files within the main project.. it just got rid of all the trouble three20 was giving me (and they are lots..) btw i tried replacing three20 with Nimbus.. but Nimbus was lacking on some of the features that my project was using three20 for.. so Nimbus wasn't helpful.
set skip install to yes under build settings for all other sub projects/static libraries and switched the copy headers from public to project under build phases
most importantly: under the sub libraries.. under build phases i ensured that copy files destination was changed from Absolute path to products directory.
and that was it!
hint: to get an idea of the offending files that's causing your archive to create an archive file rather than an ipa do this:
Select the archive and click the Distribute button.
Select the 'Save Built Products' option.
Hit Next and Save.
Browse the created directory in Finder.
The 'libraries' subdirectory will identify the libraries that you need to set the Skip Install to Yes.
in some cases usr/local/include will identify the culprit header files you need to move from Public to Project or the files that you have to change from absolute path to products directory. but that directory (ie usr/local/include) varies depending on your sublibrary directory structure
Three20 has't update in long time.And it has many bugs.set up this framework is very hard.
you can try nimbus.It come from three20.
Nimbus' Background
Nimbus has been built with much inspiration from the Three20
framework. That being said, there are a number of fundamental problems
with Three20 that Nimbus works very hard to avoid. Among them:
Poor documentation. Spaghetti dependencies. Suffering from a "kitchen
sink" complex. A complex build structure. An enormous number of
difficult-to-solve bugs. Next-to-zero test coverage. For its
weaknesses, Three20 does provide a good deal of value through its
feature set. It is used in over 100 apps in the app store by companies
such as Facebook, LinkedIn, Posterous, Meetup, and SCVNGR.
Nimbus hopes to one day provide as much value as Three20 does on a
feature-by-feature comparison, but with the invaluable benefit of
sublime documentation and test coverage.

"ld: library not found for -lXYZ" means what? What are the different possibilites?

What are the different possibilities when this error can occur?
What are the things one should look out for, in order to get rid of this?
What if XYZ is an static library directly added to project?
It means you are trying to link to a library which is not found by the system. In your case that appears to be a simple static library. You should check the following:
Look for the corresponding item in red among your project files, with special attention to the Frameworks group (that's where people normally put libraries). If you find one, fix the path or just remove and re-add the library manually.
Repeat this in the Link Binary with Libraries entry under the Build Phases tab in the project/target settings.
Check the Library Search Paths entry in the Build Settings tab in project/target settings. Make sure the path to your libXYZ.a file is listed there.

how do I reference a separate project in xcode 4?

How do I reference another project which has code I wish to leverage in XCode 4. In particular I'm trying to make use of the NSDate extensions from here.
Some notes:
I was assuming I should probably reference rather than trying build a framework
I tried copying the existing "Hello World" xcode project file across into my project, however this didn't seem to work
Do I need to create a new "Target" based on "coco touch static library" option?
Then would I need to Edit the current Product Scheme so that when I build the new target would build
What do I need to do on my project side exactly - should going Add Files, and choosing the extensions Xcode Project File be enough?
thanks
I was assuming I should probably reference rather than trying build a framework
yes, reference and link with it, unless you need only a bit of it. at this stage, separating the bits you want may be an advanced topic (depends on the lib's layout/depends as well). you should prefer to reference and link because it will normally minimize your maintenance time, especially if you use it in multiple projects.
I tried copying the existing "Hello World" xcode project file across into my project, however this didn't seem to work
you don't create a project, you add the library's xcode project to your app or library, set the lib as a dependency, add the library to your search paths if needed, then link with the library.
Do I need to create a new "Target" based on "coco touch static library" option?
no
Then would I need to Edit the current Product Scheme so that when I build the new target would build
no. you configure it as a dependency. you may need to alter the lib's build settings if there is a major conflict, which the linker or compiler would point out.
What do I need to do on my project side exactly - should going Add Files, and choosing the extensions Xcode Project File be enough?
start with the process outlined above.
There is no reason to bring in an actually project. Either you can bring in the source files themselves and you could even use the same exact files instead of copying them if you want. However, if you have more than just a few files, and you don't think you will be changing the code much, then creating a static library would probably be the best option.

XCode: Linking projects inquiry

I have 2 projects and I want to use in the first project, a class (i.e. view controller) of the second. Instead of importing all the files of the second project in the first one, is there a way to link it like a framework or library?
I tried the following unsuccessfully:
Dragged-dropped SecondProject.xcodeproj and checked SecondProject.app as a target
Added it as a dependency project in the first project dependencies
Pointed to the header files by adding in the "Header Search Paths" a path pointing to the second project which I copied in a subfolder of the first project.
When I include "SecondProjectViewController.h" I get no errors but when I try to instantiate it I get the "OBJ C referenced from" error.
Any help is deeply needed and appreciated! =)
F.
As an experienced developer I would suggest not sharing code this way across projects. The simple reason is that changes in one project will then directly effect other projects, often rendering them un-compilable. For example, if you share a controller class and decide to implement a change with a new import, then any project that uses that class will be broken until you open then in xcode and ensure that the imported class is available.
A better method is to compile your first project as a static library or framework. I'd also recommend ensuring that it is version some way. For example, in my projects I create static frameworks and store them in a directory called "v0.0.1", "v0.0.2" etc.
The framework can then be dragged and dropped into a second project to use it. The second project then refers to it via the directory path. The advantage of doing this is that if I then change the first project, the second one if not effected by the changes until I choose to update the frameworks path.
Sharing files between projects will work for small cases, that being 2 or 4 projects, but once you have more than that it rapidly becomes un-manageable.
You have only a few steps to go:
4) in First project, click the disclosure triangle in the Groups and Files section for the Second Project reference. this will display the targets of Second Project.
5) Drag the target reference (e.g., static library) from Second Project to the target in First Project's link phase.
That should clear up all the linker errors for the symbols which exist in Second Project's library. Of course, you'll have to remove those sources (based in second Second) which are compiled and linked from First.
Managing static libraries for huge codebases is dead easy this way (although I prefer the build up to the minute (as well as several build variants), and don't reference archived binaries as Derek does). Learning to minimize changes which break builds takes time to learn. dynamic libraries are a bit different - depending on their distribution, you may want to version (as Derek outlined). It's good to share, but you should put the shared exported symbols in a library, which is a dependency of both apps. Just be careful not to add too much unnecessary objc symbols to the library - objc symbols and their references cannot be stripped from the final executable and they will cause runtime collisions if they appear in two images (dylib, app, static lib) within the same process.
You can add the view controller's files to your 1st project regardless of where they are on disk -- the project will make a reference to their location.

How do you add a resource to a .bundle/wrapper.plug-in?

Sorry for the n00b question, but I have no more hair to pull. =(
I'm building my iOS project using XCode and have a reference to another XCode project, to make this work I also need to reference the bundle-file. The developer who built the project and bundle wanted to organize things and thus put all the images inside of this .bundle-file.
Now my question is this:
How do you add a file/resource to a .bundle file? -> http://grab.by/7p3Y
The file type of the bundle is: wrapper.plug-in -> http://grab.by/7p3W
The files I add by right-clicking and selecting add existing files all end up in the project not in the bundle resource.
Any kind of help will be most appreciated! Also an indication if this is common or a custom solution?
Best regards
Abeansits
Update:
As usual the problem was me, I'm blaming this on low sugar levels. =(
All you need to do is add a file to the bundle manually and it will show up in XCode.
As I wrote in the question, the solution is really simple. Just add the files you need inside the project to the bundle. Since the bundle is actually a folder, you can right click it an select show content. Anything you later add to the folder will show up in the project.
I guess this confused me since usually when you add resources to your project you need to do this through XCode.