Web hosting

Tuesday, December 13, 2011

My Static Library

Hi, Friends

We will see how to create static library and how to use in another project.

=====================================================
Create a static library
=====================================================
  •  Open the xcode and select the "Cocoa Touch Static Library" under "Framework & Library".


  •  Give the name of your library like "MyStaticLibrary".
  •  Now when you click on the "MyStaticLibrary" project and select the target, you will see the following screen.
  •  Make sure all the settings should be according to the above image. (Don't worry it should take automatically).
  •  Then create a New File with "NSObject" class. Name it "MyTestClass".
  •  Now click on the header file which you want to use in another project. and in "Target Membership" , you will find our static library, please make it public as below image,



  •  Now make the MyTestClass.h like below,
          #import <Foundation/Foundation.h>

          @ interface MyTestClass : NSObject

          - (NSString *) GetStringFromMyStaticLibrary;

          @end
  • And MyTestClass.m File like below,
            #import "MyTestClass.h"

           @implementation MyTestClass

           - (NSString *) GetStringFromMyStaticLibrary
          {
               return @"From My Static Library";
           }

           @end

Hey! It's done. Your static library is ready to use.


=======================================================
Use your static library
=======================================================

  •  Create s simple view based project.
  • Right click on the project name, click on "Add files to TestMyStaticLibrary" and add you static library project. see below,


Choose from the location where you store your static library.
  • After adding the static library your workspace looks like below,

  •  In the "TARGETS" add the static library to "Linked Binary With Libraries", and also add the Target dependencies like below,



  •  In the User header search path "$(BUILT_PRODUCTS_DIR)".
  • Finally add the header file in the appDelegate.h
          #import "MyTestClass.h"
  • Now build the project, you can see that your project build successful means we get success to use static library.
========================================================

You can download the source code from Here

Please send your suggestion and reviews it is very important for me. Thanks




No comments:

Post a Comment