Thursday, July 12, 2012

How setup and use framework in your workspace.


Introduction
In Xcode 4 several new concept were introduced, one of them is the workspace.
I had the problem of how to reuse code in several projects. The solution on iOS was to create a static library. If you develop the code for the Mac OS you create a framework.
It search in the internet for a good description of how to setup a framework project and how to use a framework in application. Apparently none of the solutions and guides fulfill my requirements. Partly the setup dirty constellations or lead to manual tasks.
Here some of my requirements:
  • The framework project shall not be a subproject of the application project.
  • The result shall be Mac Store compliant
  • The result of the framework project shall be a correct framework and can be used as other frameworks.
I didn’t cover (yet) topics like: 
  • The version feature of frameworks.
  • The possibility to add resources 
  • The different kinds of installations because of the Mac Store requirement. 
During my research I found several questions on http://stackoverflow.com which address this problem. The following list I analyzed.
The following blog entry give some good hints, but the proposed solution does not fulfill my requirements:
The Framework Programming Guide provide a good overview what you can do with a framework. 
In general there are two topics you have to cover:
  1. The configuration of the framework project for the generation of the framework bundle.
  2. The setup of your application to use the framework.
The provide a more vivid description all steps based on source code of the example from the following blog entry: http://www.cimgf.com/2008/09/04/cocoa-tutorial-creating-your-very-own-framework/ and the results are all put github.com.  
For this description I used Xcode 4.3.2 to get the default configuration of the the different projects but updated during the work to Xcode 4.3.3.
In Xcode 4.3.2 I had a problem with the dependancies which seems be fixed in 4.3.3.

Setup the framework project
In the empty workspace we create first a framework project (File -> New -> Project -> Cocoa Framework. I expect you used Xcode not the first time therefore I skip all the basic stuff :) I call the project “Framework” and use ARC.  After the import of the example files to the project it looks like this:


The first step is to define the public headers:



Therefore we move the related setting of the build phases the public headers in the public section. I expect here the code is correct and at the end the build process deliver the product. 
The last step is you have to setup the target:



Here it doesn’t matter if you show the target. The flag “Shared” for the Framework project seem important but tests with Xcode 4.3.3 showed the behavior is the same if this flag is set or not. Do you get other results?
Configure the application project
Similar to the first chapter, we create a new application project by (File -> New -> Project -> Cocoa Application). I call it “App” and use again ARC (doesn’t matter).  After the import of the Test project files all looks like this:



As you see in the source code, the import statement uses the syntax for frameworks not for common header files.
Now we have to update the project settings:
As usually for all frameworks you have to add to the linker configuration on the summary view of the application target. After that the framework reference will appear in the project browser. I moved it to the framework group.



If you build now the “App” project it should compile without any problem. You may ask how it knows its dependencies? Well the answer you find in the scheme edit dialog (press command “<“ and switch to the build settings). Here you should see this:



The setting “Find Implicit Dependencies” is by default enabled and the result is Xcode detect the relationships between the projects and their targets and build them. 
This may cost additional time in big project therefore you can disable this and add the targets explicit in the list below.
One thing is missing, as you maybe read in the Framework Programming Guide there are several possibilities to install a framework. For the Mac Store the option of “Embedding a Private Framework in Your Application Bundle” the common solution.
The configuration for this option looks like this:



The create this configuration you add a build phase “Add Copy File” and drag and drop the framework from the App in the Project Navigator to the phase. I had no luck by pressing the plus button and adding it.


Take care that your FRAMEWORK_SEARCH_PATHS setting of the App project is empty.
GitHub
The sample project you can find on GitHub : https://github.com/zehrer/FrameworkExample

Further links

(c) Stephan Zehrer 2012 - Vesion 0.7

Saturday, February 19, 2011

Static Library in iOS (Xcode)

As you can read in the following blog entries
static libraries are the best way to reuse code between several iOS projects.
In the second tutorial (part1) they define the BUILT_PRODUCTS_DIR to have a shared build output locations. I prefere here a bit different settings:
  • /Users/Shared/${USER}/products (Place Build Products in)
  • /Users/Shared/${USER}/products/Temp (Place Intermediate Build Files in)
This separate the real products (as. e.g. a static library and its header files) and the all the other build results (e.g. object files).
Additional this setting you can simplify you search path for header files. The source tree setup of the tutorial is not required therefore.
You can set you "Header Search Path" to
  • ${BUILT_PRODUCTS_DIR}/usr/local/include
The advantage is this setup work even independent of the configuration and therefor it is sufficient to define it for "All Configurations" either for each target or even for the project.
Hope this helps a bit ..
Stephan

Sunday, January 9, 2011

No languages settings in Mac Chrome

Seems there is no big chance to change the language settings in mac chrome.

Well even I am a native German I use in default the English UI. So my preferred language order (in system settings is English ,Deutsch ...

Seems Chrome only care's about the primary language but in some cases I like to have a translation from English to Germany ... seems this is at the moment not possible with chrome, isn't it?

in Bezug auf: Fonts, languages, and encodings : Basic browser settings - Google Chrome Help (auf Google Sidewiki anzeigen)

Saturday, December 27, 2008

Open VMware Tools on Ubuntu 8.10

Hey,

I just finally installed the latest version of the Open Virtual Machine Tools (2008.12.23) on my Ubuntu 8.10 installation (2.6.27-9-generic) under VM Ware Fusion (2.0.1).

Primary based on this HOWTO (first hit i found on google).

Under the expectation you downloaded the source package and you are in the following folder
cd open-vm-tools-2008.12.23-137496
You need some (additional) libraries and packages:
sudo apt-get install build-essential
sudo apt-get install linux-headers-$(uname -r)
sudo apt-get install libdumbnet-dev libdumbnet
sudo apt-get install libicu-dev
Cause I have no X development lib installed I run all with the following parameter
./configure --without-x && make
Afterwards I could install to tools:
sudo make install
We will see what is working now and what not..

Greetings and Happy New Year


Sunday, March 16, 2008

Test RSS2Email

Well let's see if my new RSS2Email is working :) ...

Friday, February 8, 2008

Native support of OpenID in Firefox

A new enhancement is suggested for Firefox. Native OpenID support.

Yes their are AddOns already available but why an extra AddOn
Now after MS is in the boat ... what will happen with IE 8/Vista?


So vote for native support: https://bugzilla.mozilla.org/show_bug.cgi?id=416359

Monday, January 7, 2008

morzilla.org on the path to OpenID

Now after years of discussion mozilla.org is on the path to support OpenID. At least for the sub project "Bugzilla". It is now on the roadmap for on of the next versions ( 3.2 or 4.0). Sources: Bugzilla

But you can vote for more OpenID support on mozilla.org. Think about the possibilities e.g. of "native" support in one of the big browsers. Vote here

Yes Scott 2008 will be great ;) ... btw Happy New Year!