How to create framework in Xcode


1. Step 1 :: Create a Cocoa Touch Static Library

Go  Xcode—> New Project —> iOS —> Framework & Library —> Cocoa Touch Static Library —> Named you app .

Screen Shot 2015-05-14 at 2.04.37 PM

Step : 2 Delete .m File from app , Select Move to trash.

Screen Shot 2015-05-14 at 2.08.02 PM

Step 3 : Open AppHelper.h and delete all content . And add

#import <UIKit/UIKit.h>

Click Project Navigator –> Targets –> Builds phases –> Link Binary with Libraries –> Add UIKit framework.

Screen Shot 2015-05-14 at 2.12.47 PM

Step 4:  Click on Editer –> Add Build Phase –> Add Header Build phase

Screen Shot 2015-05-14 at 2.18.57 PM

Step 5 :: Drag n Drop AppHelper.h in Public header

Screen Shot 2015-05-14 at 3.14.27 PM

Step 6: Go to Build Setting and Search public header . Double click on the Public Headers Folder Path setting and enter the following in the popup:   include/$(PROJECT_NAME)

Screen Shot 2015-05-14 at 3.23.14 PM

Step 7: Create New class assume CommonCode , And write you code for which you want to make framework. and Import it in AppHelper.h. Also remember make CommonCode to public.

Screen Shot 2015-05-14 at 3.39.37 PM

Note :: You can add more class similar type but make sure , keep minimum class public.

Step 8::  Since you’re creating a framework for others to use, it’s best to disable both and let the user choose what’s best for their project. To do this, using the same search field as before, update the following settings:

  • Dead Code Stripping – Set this to NO
  • Strip Debug Symbols During Copy – Set this to NO for all configurations
  • Strip Style – Set this to Non-Global Symbols

Build and run. There’s not a lot to see yet, but it’s still good to confirm the project builds successfully and without warnings or errors.

To build, select the target as iOS Device and press cmd+B to perform the build. Once completed, the libAppHelper.a product in the Products group of the Project Navigator will turn from red to black, signaling that it now exists. Right click on libAppHelper.a and select Show in Finder.

Here You have created a static library But not Framework.

For creating Framework , You also need to follow some more Step.

There are a couple of things that make a framework distinct:

  1. The directory structure. Frameworks have a special directory structure that is recognized by Xcode. You’ll create a build task, which will create this structure for you.
  2. The Slices. Currently, when you build the library, it’s only for the currently required architecture, i.e. i386, arm7, etc. In order for a framework to be useful, it needs to include builds for all the architectures on which it needs to run. You’ll create a new product which will build the required architectures and place them in the framework.

Step 1:: Go to Editer –> Add Build phase –> Add Run Script Build Phase

Screen Shot 2015-05-14 at 3.34.19 PM

Step 2. Make double click to Rename it as named Build Framework  and

Paste the following Bash script into the script field:

set -e
 
export FRAMEWORK_LOCN="${BUILT_PRODUCTS_DIR}/${PRODUCT_NAME}.framework"
 
# Create the path to the real Headers die
mkdir -p "${FRAMEWORK_LOCN}/Versions/A/Headers"
 
# Create the required symlinks
/bin/ln -sfh A "${FRAMEWORK_LOCN}/Versions/Current"
/bin/ln -sfh Versions/Current/Headers "${FRAMEWORK_LOCN}/Headers"
/bin/ln -sfh "Versions/Current/${PRODUCT_NAME}" \
             "${FRAMEWORK_LOCN}/${PRODUCT_NAME}"
 
# Copy the public headers into the framework
/bin/cp -a "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}/" \
           "${FRAMEWORK_LOCN}/Versions/A/Headers"

Screen Shot 2015-05-14 at 3.39.37 PM

Step 3: Now, select the AppHelper static library scheme and the iOS Device build target, then build using cmd+B.

Right click on the libAppHelper.a static library  and once again select Show In Finder.

Your Framework is ready to use Now


Best Of Luck

Sunny Singh

Lineage Technology

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: