Objective-C: Can't #import my Framework - objective-c

I'm just learning Objective-C, so this is going to be a pretty basic question. I've created a Mac OSX Cocoa Application and added it to a Workspace in XCode 4.
I also created a Cocoa Framework project named "Module" and added it to the same Workspace. By default XCode created a Module.h and Module.m for me which I've left unchanged.
I've seen lots of articles about how to add the framework to the project by going into the Build Phase and clicking the + in the "Link Binary With Libraries" section. I've done this and now see a toolbox in my main Application project that says "Module.Framework"
So now my next question is - how do I #import that into my main app? I tried various combinations using " and <, but all attempts report as file not found.
Help? :)
EDIT: Added some screen shots

As long as Module.framework is in your project (your main project, not the other project), you should be able to use #import <Module/Module.h>. Also, make sure you have set up a dependency so Xcode knows to build your framework before trying to build the main project.

Related

Release a cocatouch framework

I have made a library that make by swift cocoa touch framework, and now I need to export it to file .framework that can import for another project. In fact, I'm workground that copy the framework from product forder, but I think it is not a correctly solution (such as it may be archive and export, but I can't do it). Please help me. Thanks.
If I understood correctly you made a swift framework and want to include the framework to another project.
You can just drag the framework .xcodeproj from Finder to your new project and start using it.

Xcode 6.1 doesn't recognize Foundation Classes

I'm newbie in Apple developing, but im trying to develop an osx applications. I have yosemite as OS and Xcode 6.1 as IDE. Everything was ok 3 days, but at some random moment, my Xcode showed me this:
Everything covers with an errors.
What i did trying to resolve the problem:
Clean
Clean build folder
Delete derived data (in Organizer menu)
Reinstall Xcode
I even install Xcode 5 (but it don't support swift)
That erros follow me even in NEW project (with just one class AppDelegate.swift) and in any new class with any object like NS*.
What's happen with my Xcode and how i can fix it?
I forget to say, my project building and compiling without any error or warning. All errors disappears when i press button "Build".
UPDATE #1: i made: import Foundation - open it, and i did not find errors classes there. There are a lot of classes, such as NSCache and etc, but there are no NSTextField and etc.. Where are they?
UPDATE #2:
I've found that Xcode see classes which directly contains in Foundation moduel.
Also i got this window:

Xcode: How to have shared code (i.e. framework) between main project and plugin bundle

In my project I had two targets, 1) The main application which loads 2) a bundle of plugins. I have started to have objects which need to be available in both targets, so naively tried to compile them separately in each target (producing warnings about having different implementations: Class X is implemented in both Y and Z. One of the two will be used. Which one is undefined.)
To solve this I decided to create a framework, so I added a framework, but I don't know how to make it so that a) both the main app and bundle access the framework (via the compiled framework, and not just through the headers in the project), and so the framework is compiled when I run the project.
If you know how to do this, thanks!
Here are the steps I followed:
Create a new framework in the project , copy all the shared code over.
In the main header of the framework, include the headers of all the shared code.
Build the framework to test it builds (e.g. select the scheme of the framework and click play)
Go to the Build Phases of both the Application and the Plugin Bundle and add the framework to ‘target dependencies’ and ‘Link binary with libraries’
To include the frameworks stuff in code in the app and bundle, just use the main header, and use <> rather than “" e.g if your framework was called Foo use #import
When it comes to deploying, there might have to be some fiddling with where the framework gets installed, currently it gets put alongside the app itself, rather than inside, but I will probably fix that later :)

Xcode: how to build a static library project correctly?

This question will be easy for Xcode pros but for a MonoTouch developer it seems to be impossible to resolve. :-)
I'm using Xcode 4.5 and I want to target iOS 5.1 and above and iOS Simulator 5.1 and above.
I have a a library project here and it is coming with a prebuilt binary named "DemoLib" (no extension and it is 11MB in size). The library is a fat lib for Simulator and iOS 5.1+.
I can use that library without any problem.
However if I try to build the library myself, I end up with a "DemoLib.a" file (notice the extension and the size of 30MB). How can I get the same build result? What is a .a file compared to the file without extension?
I tried to build the project "for running", and "for archiving" in Xcode. Both results in the same 30MB .a file.
I was expecting some dropdown in Xcode where one could select "DEBUG" or "RELEASE" build and the latter one would create the smaller lib.
Of course I could never tell without seeing the framework's project file. Having said that, there is an excellent guide to creating and compiling iOS frameworks here: https://github.com/jverkoey/iOS-Framework
Using the above guide, you should be able to recreate your framework's project from scratch, add the files you have to it, and properly compile it.
Hope this helps! :)
Did it come with a Makefile? Create a new target, set the build settings of the target to what's in the Makefile, then set your project to depend on that new target.
A file with the .a is a static library, which means it depends on nothing external and all the code it needs is compiled inside it. I think no extension generally implies dynamic library, which means it'll depend on some dependencies being present on your system to link against. Maybe that's why the .a is so much bigger. I think Xcode will build static by default because iOS does not allow the use of dynamic libraries.
The dropdown for what to build is in your scheme. Command+shift+< to view your scheme. Within the scheme you can edit which environment each method of building will use.

Adding a framework to XCode 4

of course i did research before posting my question.
I looked at
How to "add existing frameworks" in Xcode 4?
Adding Framework in Xcode 4
Adding an OpenGL framework in Xcode 4
XCode 4 adding dylib
but whole thing is becoming wrong.
My goal: Add (CorePlot) framework to XCode Mac project (not an iPhone one)
My environment: OSX Lion 10.7, SDK Lion, XCode 4.1 (4B110)
My steps:
Opened XCode, created new project
Downloaded CorePlot into my libraries directory (like ~/Applications/LIBS)
Opened project preferences, via (+) opened dialog to add framework
Add existing framework (+ copy files to dest. group if needed)
Selected directory was ~/Applications/LIBS/CorePlot/Binaries/MacOS/CorePlot.framework/
DnD CorePlot to Frameworks Group
Added CorePlot to Build Phases > Link Binary with Libraries
and ran my project
what I got is this error message:
dyld: Library not loaded: #loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot
Referenced from: /Users/username/Library/Developer/Xcode/DerivedData/metralight-hjuvuwlhgohrtdeepvcymnsaxomc/Build/Products/Debug/metralight.app/Contents/MacOS/metralight
Reason: image not found
And in fact, when I looked into given directory (app bundle) there was no directory Frameworks and so the linking cannot be successful
I have searched one more, and found, that I can create Build Rule and copy files into final binary bundle via some script, but is this only way how to do this?
Isn't there some option to just turn on/off copying linked frameworks to final bundle?
Note that CorePlot target '.framework' has Dynamic Library Install Name set to #loader_path/../Frameworks/CorePlot.framework/Versions/A/CorePlot, so it is looking in right place in final binary bundle
After adding framework via "Add existing framework"
Go to Project Settings > Build Phases
In right bottom corner click Add buid phase > Copy Files
Select Destination > Frameworks
Drag&Drop framework to files list
And that's it.
Another important detail here - you must have the "Runtime search path" to be defined in the projects, it's empty by default.
Something like this:
LD_RUNPATH_SEARCH_PATHS = #loader_path/../Frameworks