Hi Friends,
In this tutorial I will show you how to create a simple Static Library in Xcode 3.2 and then how to use it in our project.First,I will be creating a Static Library and then will show you how to make use use of it in our code.I am providing you with the following steps to do so.
Lets Begin,
1. Create
a simple Window-based project,we will call it as ‘SampleLib’.
2. Drag
all .h and .m files (which you want to include in your library )in the ‘Classes’ folder of SampleLib project.
3. Right
click on ‘Targets’ ->Add ->New Targets…
4. Select
‘Static Library’.
5. Name
it as ‘MyLib’
6. Select
‘build’ tab from the newly pop up window.(That window name is ‘Target “MyLib”
info’) or select ‘MyLib’ and press ‘windows+I’,you will get the same window
i.e. ‘Target “MyLib” info’.
7. In
the ‘Linking’ section set ‘Other Linkers Flag’ to ‘-ObjC’.
8.
Now you will see MyLib and Mylib.a in your project.
9. Drag
all your (only).m files which you added in step2 above to ‘Targets->MyLib->Compile
Sources folder.
10. Delete
all the files from Targets->SampleLib->Compile Sources Folder.
11. Right
click on Target->’SampleLib’ then Add->Existing Frameworks and select
‘MyLib.a’ framework in the list.
12. Right
Click on Targets->SampleLib select ‘Build SampleLib’.
Now
Your Library is created.
2.Using Static Library in iPhone
1. Create
new project where you want to use the Library,name it as ‘TestLib’.
2. Drag
‘MyLib.a’ file and all .h files which are included in the library to ‘TestLib’.
3. For
every xcode file wherever you are using 'SampleLib' library code,you need give
'.mm' extension to it.Because we need to provide.mm extension to all the xcode
files instead of '.m'.
3. Now
you can simply use the static library methods by calling them from your
‘TestLib’.
Here you can Download Static
Library code StudentLib Project.
Here you can
Download code to use SampleLib in UsingStudentLib Project.
what about the xcode 4.3? and ios5?
ReplyDeleteHi Nicos,Please go through the following Link :
Deletehttp://www.icodeblog.com/2011/04/07/creating-static-libraries-for-ios/