How to create custom iOS Framework using xCode ?

Posted by Unknown Jumat, 28 September 2012 0 komentar
Are you thinking of making Product or Library ? Custom framework will help you for sure.

You might have question while using FB, Twitter framework that how did they create ?
You can not modify a single line of FB framework !!!

Let's think, where we can use such frameworks ?
We already read two example, FB and Twitter.

Let's think for another use, some piece of code you replicate in each project. for example these days each project needs to use WS(web services), Right ? why not create a framework for the same ???

Ok, Before you leave reading my blog, Let's get started with making Custom iOS framework, Here we go...

Below are the steps to generate Universal (Device and Simulator) framework with xCode 4.5 GM Seed

Step 1: Create new project
Create new project, select Project template as "Utility Application" (Suppose Project name : "iOSFramework") 
Create new Project
Create new Project

Step 2: Create new target
Navigate to main xCode menu, File => New => Target...


Create new Target
Create new Target
Suppose I named it as "iOSBundle"

Step 3: Remove files .plist,.pch and language
Navigate to project navigator, you can find group for "iOSBundle", Remove .plist, .pch and language files of "iOSBundle" only.


Remove files form bundle
Remove files form bundle

Step 4: Check build settings
Check below list of build settings for "iOSBundle" target only.

  • Base SDK: Latest iOS (iOS X.X).
  • Architectures: Standard (armv7, armv7s) in xCode 4.3 Standard (armv7) 
  • Build Active Architecture Only: NO
  • Supported Platforms: iOS, in xCode 4.3 (iphonesimulator iphoneos)
  • Valid Architecture: $(ARCHS_STANDARD_32_BIT) 
  • OS X Deployment Target: Compiler Default.
  • Dead Code Stripping: NO.
  • Link With Standard Libraries: NO.
  • Mach-O Type: Relocatable Object File. 
  • Other Linker Flags [optional change, depends upon your framework]:  -ObjC
  • Info.plist File: empty
  • Wrapper Extension: framework 
Step 5: Build Phase => Link Binary With Libraries => remove all references

Step 6:  Add Source Code

Add your source code and resource files under "iOSBundle" target.

In this tutorial I will create only class called "Utility"

Utility.h



Utility.m





Step 7:  Add Copy Header and Compile Source

Go to Build Phase => Add Phase => Add Copy Header


Add Copy Headers
Add Copy Headers


Add all header files in following sections


Public: Headers that other developers must know in order to work with your framework. In the final framework product, these headers will be visible even to Xcode.

Private: Headers that is not necessary to other developers, but is good for consult or for reference. These headers will not be visible to Xcode, but will be in the framework folder.

Project: Headers that the other developers nor Xcode have access. In reality these headers will not be placed in the final product, this is just to instruct the compiler to create your custom framework.

I have added "Utility.h" to public header

Add below file to Compile Source section
Add .m, .cpp, .mm,.c extension files goes to this section for compilation.
In our case it will be "Utility.m" file

Build Phase
Build Phase
If your Framework includes images, sounds, nibs etc resources, put them under Build Phase => Copy Bundle Resources

Step 8: Build configuration

Navigate from main menu,

  • Product => Manage Schemes
  • Select "iOSBundle"
  • Click edit
  • Go to "Run" Section
  • Change build configuration to "Release"

Step 9:  Check build settings

Perform below changes in build setting of "iOSBundle" target

  • Precompile Prefix Header: NO
  • Prefix Header: empty
  • Generate Debug Symbols: NO
Step 10: Build Project 

  • Select "iOSBundle" scheme
  • Build project for "iOS device" (⌘-B)
  • Build project for "iPhone 6.0 simulator" (⌘-B)
Build Project
Build Project
Step 11: Add new target (to Create Universal Framework)
At this moment you can see two different framework in you project's release folder, one for Simulator and one for Device, now we need to merge both framework.

For that let's create one new target,
  • Navigate through, Main Menu => File => Target...
  • Select "Aggregate" template.
  • Named target as "UniversaliOS"

Aggregate Target
Aggregate Target


Step 11: Add Run Script to Aggregate target

Add Below, Run script to Aggregate("UniversaliOS") target.
Go to Build Phase => Add Build Phase => Add Run Script

Paste below in Shell section.




In Above Script, Replace "<FW_NAME>" with your Framework name, In my case "iOSBundle"


Step 12: Build Project with Aggregate scheme

  • Select Aggregate("UniversaliOS") Scheme 
  • Select iOS device
  • Build Project (⌘-B) 
Build Project for Aggregate
Build Project for Aggregate
Step 13: Copy Framework and Test

From Finder Navigate to Build folder of you Project
Under Products folder you can find your merged Framework

For me path for Framework is below,

/Users/jaym/Library/Developer/Xcode/DerivedData/iOSFramework-doeqysadgntrrlguuvcivuhapnlr/Build/Products/iOSBundle.framework


Copy this Framework to safe place for future use.

Let's test the Framework,

  • Create new project
  • Go to build phase
  • Navigate to "Link binary with Libraries"
  • Select "Add Other", add your(iOSBundle.framework) Framework.
  • Go to AppDelegate.h
  • Import framework header like this (#import <iOSBundle/Utility.h>)
  • Now, Create object of Utility and try accessing methods of class

Thanks for reading the Article!

Keep in touch for more Articles.

Follow me @ Just iOS



TERIMA KASIH ATAS KUNJUNGAN SAUDARA
Judul: How to create custom iOS Framework using xCode ?
Ditulis oleh Unknown
Rating Blog 5 dari 5
Semoga artikel ini bermanfaat bagi saudara. Jika ingin mengutip, baik itu sebagian atau keseluruhan dari isi artikel ini harap menyertakan link dofollow ke https://apk-zenonia5.blogspot.com/2012/09/how-to-create-custom-ios-framework.html. Terima kasih sudah singgah membaca artikel ini.

0 komentar:

Posting Komentar

Trik SEO Terbaru support Online Shop Baju Wanita - Original design by Bamz | Copyright of apk zenonia 5.