How can I create objective-C Framework for iOS Application

后端 未结 6 810
星月不相逢
星月不相逢 2020-12-15 01:13

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 projec

6条回答
  •  无人及你
    2020-12-15 01:44

    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  
    

    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.

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

    Cross-platform =>Aggregate 
    

    5) Add Run Script

    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 .

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

    2) Build for simulator.

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

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

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

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

提交回复
热议问题