81: Short embedded Frameworks Example

Problem: (as per example 80) we want to create our own library of pre-compiled code that we can include as part of our applications. We want to be able to continue developing the library without having to re-install it in each application that uses it.

Plugin developers note: These procedures may be used in the context of embedded plugin based applications, i.e. where the plugin files are copied into the application bundle.

This example is a short version of my example 80. Because it is in summary form it should be easier to follow, nevertheless you may find it convenient to have the graphics of example 80 displayed in a window next to this one.


Answer: on the framework side

  • Use XCode to create a Cocoa Framework of Objective-C .m and .h files. Call it Framework81.
    These will include a public header file or files through which the application will access framework functionality.

  • Define the installation path.
    To do this: select Groups & Files->Targets->Framework81 and click the Info button.
    Choose the Build tab and find the Installation Directory entry.
    Set this to the string @executable_path/../Frameworks

  • Expose the header file(s).
    Still with the Framework81 entry selected set the Role of the appropriate header(s) to public

  • Build.


Answer: on the application side

  • In XCode create a New Application and call it App81.

  • Add the Framework.
    In Groups & Files Control click on Frameworks->Linked Framework and select Add->Existing Frameworks.
    When the Apple frameworks panel comes up click the Add Other button, navigate to the framework folder and choose build->Debug->Framework81.framework and Add

  • Embed the Framework in the application bundle.
    Control click on Groups and Frameworks->Targets->App81.
    Choose Add->New Build Phase->New Copy Files Build Phase.
    When the Info panel appears set the Destination to Frameworks.
    Now drag Groups & Files->Frameworks->Linked Frameworks->Framework81.framework to Groups & Files->Targets->App81->Copy Files.

  • Build and Run.
    If everything has build correctly there should now be a copy of the Framework81.framework file inside App81->build->Debug

  • Update application main so as to access one of the framework methods.
    Build and Run and observe that you got the correct output

  • Create a cross project target dependency.
    This will ensure that the application is always accessing the latest version of the Framework.
    Do Project->Add to Project
    Navigate to the Framework81 folder and select the Framework81.xcodeproj file.
    When the Copy panel appears set the Reference Type to Relative to Project.
    Select Groups & Files->Targets->App81 and click the Info button.
    Choose the General tab
    Click the plus (+) button under Direct Dependencies and select Framwork81 when the panel appears and click Add Target

  • Test the depencency by making an alteration to the Framework output.
    Go back to App81. Build and run.
    Examine the output to observe the change.



Please send me your comments

If you include your e-mail I may reply!  

Page last modified: 11:57 Monday 7th. November 2011