7

I am in the middle of creating some generic classes that can be reusable for lot of application.

For Eg: Share Functions - if we need this functionality in a project then we currently I need to add a group of classes into that project and display the view-controller in that group of files, In this view controller there is buttons and what all need to handle sharing.

what my idea is if a project need such a functionality they need to add a framework and call a function in it or display the specified view in framework ie. no code level access given to whom you do that project. so if any issue is found in that generic classes (framework) I need to fix it and recreate the framework and change in the all project that uses this framework without affecting the existing project.

I am think not only the sharing function. More like a Image Slider, a PDF Viewer , a Browser. a Cover Flow. Currently I have code for all this Functions. But it take too much time to others to integrate it and use it. If any issue found we need to change the all project source classes.

I go through several links in google

Can I develop my own objective-C Framework for Cocoa Touch Applications?

http://www.cocoanetics.com/2010/04/universal-static-libraries/

A Guide for Creating your own Library for Cocoa(touch) development

I cannot understand how it use and some of them have not explain it fully. some missing in those links.

thanks in advance

Community
  • 1
  • 1
Naveen Shan
  • 9,082
  • 3
  • 26
  • 43

6 Answers6

8

Check out this guide on creating static iOS frameworks:

https://github.com/jverkoey/iOS-Framework

featherless
  • 2,050
  • 19
  • 19
  • i got this to work with xcode 4.6.3, but unfortunately the instructions are pretty out of date. look at the issues list to find fixes. – Ben H Jul 17 '13 at 01:20
5

We created Framework in Objective c, It's work Perfect.

By Follow Below Simple Steps to create Framework

1) Create new framework as ,

In xcode select

 file =>New =>Project =>cocoatouchframework =>Next =>GiveframeworkName =>Create  

enter image description here

2) Add .h and .m files in project, which is used for create Framework.

3) Add files in Public Headers in build phases, this file will display in your framework.

enter image description here

4) Click on project name DemoFramework then select + button then select

Cross-platform =>Aggregate 

enter image description here

5) Add Run Script

enter image description here

6) Add below code in Run script to Aggregate(marge)iPhone and simulator framework.

   #  ============Script Start==============
   if [ "${ACTION}" = "build" ]
   then
   # Set the target folders and the final framework product.
   INSTALL_DIR=${SYMROOT}/DemoFramework.framework
   DEVICE_DIR=${SYMROOT}/Debug-iphoneos
   SIMULATOR_DIR=${SYMROOT}/Debug-iphonesimulator

  # Create and renews the final product folder.
  mkdir -p "${INSTALL_DIR}"
  rm -rf "${INSTALL_DIR}"
  rm -rf "${INSTALL_DIR}/DemoFramework"

 # Copy the header files to the final product folder.
 ditto "${DEVICE_DIR}/DemoFramework.framework/Headers" 
 "${INSTALL_DIR}/Headers"

 # Copy the info.plist file to the final product folder
 ditto "${DEVICE_DIR}/DemoFramework.framework/info.plist" 
"${INSTALL_DIR}"

# Copy the ResoureBundle.bundle file to the final product folder
ditto "${DEVICE_DIR}/DemoFramework.framework/ResourceBundle.bundle" 
"${INSTALL_DIR}/ResourceBundle.bundle"

# Use the Lipo Tool to merge both binary files (i386 + armv6/armv7) 
 into one Universal final product.
 lipo -create "${DEVICE_DIR}/DemoFramework.framework/DemoFramework" 
"${SIMULATOR_DIR}/DemoFramework.framework/DemoFramework" -output 
"${INSTALL_DIR}/DemoFramework"
 fi
 #  ============Script End==============

7) Now build the project in Three steps

1) Build for iPhone device .

enter image description here

You will see framework is created for iPhone device and framework location is show in derived data of project as below .

enter image description here

2) Build for simulator.

enter image description here

You will see framework is created for Simulator and framework location is show in derived data of project as below .

enter image description here

3) This is final step to create framework, select Aggregate in build option and build the application see screen shot as below . enter image description here

Finally your framework is created use this framework in any application, The Framework location is in derived data as below.

enter image description here

Hopes this easy steps help someone to create framework in objective C.

Jaywant Khedkar
  • 4,939
  • 2
  • 35
  • 49
4

I'm guessing that what you are asking for is how to create a shared dynamic library for iOS; and the long and short of it is: You can't.

The only kind of library supported is the static library; so whenever you make changes to your library; every application that uses it needs to be recompiled.

Williham Totland
  • 26,865
  • 5
  • 48
  • 68
  • This. Also, don't be fooled by looking around the OS. The OS is allowed to (and does) vend and consume shared dynamic library frameworks, non-OS developers can't. If you think about it, it doesn't buy you much on iOS: Your app runs in it's own sandbox, and to allow arbitrary shared dynamic libraries on the platform could potentially subvert that mechanism (at the very least, it complicates the matter). I won't hold my breath waiting for this. – ipmcc Mar 22 '11 at 13:03
  • thanks Williham, But I was create a framework with .a extention for using in xcode but it is C code. eg: pjzip. – Naveen Shan Mar 24 '11 at 04:28
  • Ah, but you can fake a framework that contains a static library. A single instance won't be shared across apps, so each app will have its own copy. But the framework is easier to manage than static library + headers. – Jon Reid May 18 '11 at 15:52
  • @JonReid: That might be; but from what I can see from your answer, managing the build of the framework is distinctly less easier to manage. – Williham Totland May 18 '11 at 15:57
  • True. Harder for the producer, easier for the consumer. If you're both, it may be a wash. – Jon Reid May 18 '11 at 16:55
3

http://accu.org/index.php/journals/1594 offers detailed instructions.

OCHamcrest does it by taking a copy of the OS X version of the framework, and replacing its dynamic library with an iOS static library. (Xcode 4 version coming soon.)

Jon Reid
  • 18,809
  • 2
  • 54
  • 86
  • I think this is the answer what I am searching.. But I now I am busy with some other project so I will come back with the result within a couple of week – Naveen Shan Mar 31 '11 at 04:38
  • The approach used by OCHamcrest has been to use a Run Script. I have found that this doesn't work as well in Xcode 4, so I am extracting the script from the project and will run it externally. – Jon Reid Mar 31 '11 at 14:02
  • Can you please explain how can we execute the script externally without using xcode. – Naveen Shan Jun 11 '12 at 12:52
  • Execute the script from Terminal. – Jon Reid Jun 11 '12 at 20:31
0

I built Xcode 4 templates to do this. See my answer here: Can I develop my own objective-C Framework for Cocoa Touch Applications?

Community
  • 1
  • 1
Karl
  • 12,926
  • 8
  • 41
  • 59
0

Objective-C consumer -> Objective-C dynamic framework

Xcode version 10.2.1

Create Objective-C framework

Follow Create Objective-C framework

Objective-C consumer with Objective-C framework

Follow Swift consumer with Objective-C framework

Import module to the Objective-C client code[module_name]

@import module_name;

//or umbrella or public header
#import <module_name/module_name.h>

Call a framework's code[Use of undeclared identifier]

[More examples]

yoAlex5
  • 13,571
  • 5
  • 105
  • 98