如何为 iOS 应用程序创建 Objective-C 框架

发布于 2024-10-25 02:32:55 字数 963 浏览 4 评论 0原文

我正在创建一些可重用于许多应用程序的通用类。

例如:共享功能 - 如果我们在项目中需要此功能,那么我们目前需要将一组类添加到该项目中并在该组文件中显示视图控制器,在此视图控制器中有按钮以及所有内容需要处理共享。

我的想法是,如果一个项目需要这样的功能,他们需要添加一个框架并调用其中的函数或在框架中显示指定的视图,即。没有向您执行该项目的人员授予代码级别访问权限。因此,如果在通用类(框架)中发现任何问题,我需要修复它并重新创建框架,并在使用该框架的所有项目中进行更改,而不影响现有项目。

我认为不仅仅是分享功能。更像是图像滑块、PDF 查看器、浏览器。覆盖流。目前我有所有这些功能的代码。但其他人需要花费太多时间来集成和使用它。如果发现任何问题,我们需要更改所有项目源类。

我在谷歌浏览了几个链接

可以我为 Cocoa Touch 应用程序开发自己的 Objective-C 框架?

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

为 Cocoa(touch) 开发创建自己的库的指南

我无法理解它是如何使用的,其中一些还没有完全解释它。这些链接中缺少一些内容。

提前致谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

窗影残 2024-11-01 02:32:55

查看有关创建静态 iOS 框架的指南:

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

Check out this guide on creating static iOS frameworks:

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

抹茶夏天i‖ 2024-11-01 02:32:55

我们在 Objective c 中创建了框架,工作非常完美。

按照以下简单步骤创建框架

1) 创建新框架,

在 xcode 中选择

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

在此处输入图像描述

2) 在项目中添加.h和.m文件,用于创建Framework。

3)在构建阶段在公共标头中添加文件,该文件将显示在您的框架中。

输入图像描述此处

4) 单击项目名称 DemoFramework,然后选择 + 按钮
选择

Cross-platform =>Aggregate 

输入图片此处描述

5) 添加运行脚本

在此处输入图像描述

6) 在运行脚本中添加以下代码到聚合(marge)iPhone 和模拟器框架。

   #  ============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) 现在分三步构建项目

1) 为 iPhone 设备构建。

输入图像描述在这里

您将看到为 iPhone 设备创建了框架,并且框架位置显示在项目的派生数据中,如下所示。

输入图像描述这里

2) 构建模拟器。

输入图像描述在这里

您将看到为模拟器创建了框架,并且框架位置显示在项目的派生数据中,如下所示。

输入图像描述这里

3)这是创建框架的最后一步,
在构建选项中选择聚合并构建应用程序,请参见下面的屏幕截图。
输入图片描述这里

最后,在任何应用程序中使用此框架创建您的框架,框架位置位于派生数据中,如下所示。

输入图像描述这里

希望这个简单的步骤可以帮助人们在 Objective C 中创建框架。

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.

晨光如昨 2024-11-01 02:32:55

我猜你要问的是如何为iOS创建一个共享动态库;总而言之,就是:你不能。

唯一支持的库是静态库;因此,每当您对库进行更改时;每个使用它的应用程序都需要重新编译。

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.

自我难过 2024-11-01 02:32:55

http://accu.org/index.php/journals/1594 提供详细说明。

OCHamcrest 通过获取 OS X 版本框架的副本,并将其动态库替换为iOS 静态库。 (Xcode 4 版本即将推出。)

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.)

浅笑依然 2024-11-01 02:32:55

我构建了 Xcode 4 模板来执行此操作。在这里查看我的答案:我可以为 Cocoa Touch 应用程序开发自己的 Objective-C 框架吗?

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

心清如水 2024-11-01 02:32:55

Objective-C 消费者 -> Objective-C 动态框架

Xcode 版本 10.2.1

创建 Objective-C 框架

按照 创建 Objective-C 框架

使用 Objective-C 框架的 Objective-C 消费者

遵循 使用 Objective-C 框架的 Swift 消费者

将模块导入 Objective-C 客户端代码[module_name]

@import module_name;

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

调用框架的代码[使用未声明的标识符]

[更多示例]

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]

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文