iOS UmbrellaFramework
一、umbrella framework
将几个已经封装好的 framework 封装成一个,封装的这种 framework 就是 umbrella framework。
Apple 的官方文档中明确提到了不建议自己去创建 umbrellaframework。首先先引入 Apple 的 Guidelins for Creating Frameworks 的一段:
Don’t Create Umbrella Frameworks
While it is possible to create umbrella frameworks using Xcode, doing so is unnecessary for most developers and is not recommended. Apple uses umbrella frameworks to mask some of the interdependencies between libraries in the operating system. In nearly all cases, you should be able to include your code in a single, standard framework bundle. Alternatively, if your code was sufficiently modular, you could create multiple frameworks, but in that case, the dependencies between modules would be minimal or nonexistent and should not warrant the creation of an umbrella for them
分三个部分逐步创建并使用 UmbrellaFramework:
- SubFramework:创建一个基础 framework
- UmbrellaFramework:framework 里封装 framework
- UmbrellaFrameworkDemo:使用 demo
二、创建一个基础的 framework
UmbrellaFramework(一)创建基础framework
创建一个 framework 工程:Subframework;
添加 SubSayHello 类,添加 sayHello 方法;
@interface SubSayHello : NSObject
- (void)sayHello;
@end
@implementation SubSayHello
- (void)sayHello
{
NSLog(@"say Hello");
}
@end
在 SubFramework.h 头文件中导入 SubSayHello.h
#import <Subframework/SubSayHello.h>
将 SubSayHello.h 添加到 Target -> Build Phases -> Headers -> Public,可手动拖拽;
Build Settings -> Mach-O Type 选择 Static Library 静态库
生成通用 framework
方式一:分别在模拟器和真机下编译工程,生成两个 framework,用命令行合并成一个通用的。
$ lipo -create [真机 Framework 二进制文件路径] [模拟器 Framework 二进制文件路径] -output [结果路径]
$ lipo -create /Users/cykj/Library/Developer/Xcode/DerivedData/Subframework-hkwchwbjmtuhoseinwkzbtcjxpbj/Build/Products/Debug-iphoneos/Subframework.framework/Subframework /Users/cykj/Library/Developer/Xcode/DerivedData/Subframework-hkwchwbjmtuhoseinwkzbtcjxpbj/Build/Products/Debug-iphonesimulator/Subframework.framework/Subframework -output /Users/cykj/Desktop/Subframework
注意:如果执行命令报错,可以将结果地址改为
/Users/cykj/Desktop/Subframework.xx
,生成后再将后缀名去掉。方式二:脚本生成
为 SubFramework 工程添加 Target -> Aggregate
在新添加的 Target 中添加脚本
脚本内容
# Sets the target folders and the final framework product.
FRAMEWORK_NAME=LibraryName
FRAMEWORK_VERSION=1.0
FRAMEWORK_CONFIG=Release
# Install dir will be the final output to the framework.
# The following line create it in the root folder of the current project.
INSTALL_PATH=${PROJECT_DIR}/Products/
INSTALL_DIR=${INSTALL_PATH}/${FRAMEWORK_NAME}.framework
# Working dir will be deleted after the framework creation.
WORK_DIR=build
DEVICE_DIR=${WORK_DIR}/${FRAMEWORK_CONFIG}-iphoneos/${FRAMEWORK_NAME}.framework
SIMULATOR_DIR=${WORK_DIR}/${FRAMEWORK_CONFIG}-iphonesimulator/${FRAMEWORK_NAME}.framework
xcodebuild -configuration "${FRAMEWORK_CONFIG}" -target "${FRAMEWORK_NAME}" -sdk iphoneos
echo "Build simulator"
xcodebuild -configuration "${FRAMEWORK_CONFIG}" -target "${FRAMEWORK_NAME}" -sdk iphonesimulator
# Creates install directory if it not exits.
if [ ! -d "${INSTALL_DIR}" ]
then
mkdir -p "${INSTALL_DIR}"
fi
# Creates headers directory if it not exits.
if [ ! -d "${INSTALL_DIR}/Headers" ]
then
mkdir -p "${INSTALL_DIR}/Headers"
fi
# Remove all files in the headers diectory.
for file in `ls "${INSTALL_DIR}/Headers"`
do
rm "${INSTALL_DIR}/Headers/${file}"
done
# Remove binary library file.
rm -f ${INSTALL_DIR}/${FRAMEWORK_NAME}
# Copies the headers files to the final product folder.
if [ -d "${DEVICE_DIR}/Headers" ]
then
for file in `ls "${DEVICE_DIR}/Headers"`
do
cp "${DEVICE_DIR}/Headers/${file}" "${INSTALL_DIR}/Headers/${file}"
done
fi
# copy nibs to bundle,then copy bundle to final folder
BUNDLE_DIR=${DEVICE_DIR}/${FRAMEWORK_NAME}.bundle
if [ -d "${BUNDLE_DIR}" ];then
if ls ${DEVICE_DIR}/*.nib >/dev/null 2>&1;then
rm -rf ${BUNDLE_DIR}/*.nib
cp -rf ${DEVICE_DIR}/*.nib ${BUNDLE_DIR}
fi
rm -rf "${INSTALL_DIR}/${FRAMEWORK_NAME}.bundle"
cp -R "${BUNDLE_DIR}" "${INSTALL_DIR}/${FRAMEWORK_NAME}.bundle"
fi
echo "Merge with simulator"
# Uses the Lipo Tool to merge both binary files (i386 + armv6/armv7) into one Universal final product.
lipo -create "${DEVICE_DIR}/${FRAMEWORK_NAME}" "${SIMULATOR_DIR}/${FRAMEWORK_NAME}" -output "${INSTALL_DIR}/${FRAMEWORK_NAME}"
open "${INSTALL_PATH}"
# rm -r "${WORK_DIR}"
查看 framework 支持的架构
$ lipo -info [framework 二进制文件路径]
三、framework 里封装 framework
UmbrellaFramework(二)framework里封装framework
创建 Cocoa Touch Framework 工程 UmbrellaFramework
导入 SubFramework
选择 Target -> Build Phases -> 点击左上角+号 -> New Copy Files Phase 添加 Copy Files,将 SubFramework 添加到 Copy Files,选择 Destination 为 Frameworks。
添加 UmbrellaSayHello 类,添加 sayHello 方法,并在 sayHello 方法中调用 SubFramework 的 sayHello 方法。
@interface UmbrellaSayHello : NSObject
- (void)sayHello;
@end
#import <Subframework/SubSayHello.h>
@implementation UmbrellaSayHello
- (void)sayHello
{
NSLog(@"%s", __func__);
SubSayHello * ssh = [[SubSayHello alloc] init];
[ssh test];
}
@end
UmbrellaFramework.h 头文件中导入将 UmbrellaSayHello.h
#import <UmbrellaFramework/UmbrellaSayHello.h>
将 UmbrellaSayHello.h 添加到 UmbrellaFramework 的公共 headers 中
Architectures 添加 armv7s
连接选项 Mach-O Type 不用改,选择默认选项 Dynamic Library,这意味着外层的 UmbrellaFramework 是一个动态库。
生成真机和模拟器都能用的 framework。见第二章。
四、使用 UmbrellaFramework
创建工程 UmbrellaFrameworkDemo
嵌入UmbrellaFramework,选择工程 -> General -> Embedded binaries,添加UmbrellaFramework。UmbrellaFramework 将会同时添加到 Linked Frameworks and Libraries.
工程中使用
#import <UmbrellaFramework/UmbrellaFramework.h>
- (void)viewDidLoad
{
[super viewDidLoad];
UmbrellaSayHello * ush = [[UmbrellaSayHello alloc] init];
[ush sayHello];
}
iOS UmbrellaFramework的更多相关文章
- iOS UmbrellaHeader
Lexical or Preprocessor Issue - Umbrella header for module 'xxx' does not include header 'xxx.h' fra ...
- iOS可视化动态绘制连通图
上篇博客<iOS可视化动态绘制八种排序过程>可视化了一下一些排序的过程,本篇博客就来聊聊图的东西.在之前的博客中详细的讲过图的相关内容,比如<图的物理存储结构与深搜.广搜>.当 ...
- 【疯狂造轮子-iOS】JSON转Model系列之二
[疯狂造轮子-iOS]JSON转Model系列之二 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 上一篇<[疯狂造轮子-iOS]JSON转Model系列之一> ...
- 【疯狂造轮子-iOS】JSON转Model系列之一
[疯狂造轮子-iOS]JSON转Model系列之一 本文转载请注明出处 —— polobymulberry-博客园 1. 前言 之前一直看别人的源码,虽然对自己提升比较大,但毕竟不是自己写的,很容易遗 ...
- iOS总结_UI层自我复习总结
UI层复习笔记 在main文件中,UIApplicationMain函数一共做了三件事 根据第三个参数创建了一个应用程序对象 默认写nil,即创建的是UIApplication类型的对象,此对象看成是 ...
- iOS代码规范(OC和Swift)
下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...
- JS调用Android、Ios原生控件
在上一篇博客中已经和大家聊了,关于JS与Android.Ios原生控件之间相互通信的详细代码实现,今天我们一起聊一下JS调用Android.Ios通信的相同点和不同点,以便帮助我们在进行混合式开发时, ...
- 告别被拒,如何提升iOS审核通过率(上篇)
iOS审核一直是每款移动产品上架苹果商店时面对的一座大山,每次提审都像是一次漫长而又悲壮的旅行,经常被苹果拒之门外,无比煎熬.那么问题来了,我们有没有什么办法准确把握苹果审核准则,从而提升审核的通过率 ...
- Swift3.0服务端开发(一) 完整示例概述及Perfect环境搭建与配置(服务端+iOS端)
本篇博客算是一个开头,接下来会持续更新使用Swift3.0开发服务端相关的博客.当然,我们使用目前使用Swift开发服务端较为成熟的框架Perfect来实现.Perfect框架是加拿大一个创业团队开发 ...
随机推荐
- harbor自动清理镜像
harbor定时清理镜像 分享下最近写harbor仓库镜像自动清理脚本思路,很长时间不写shell脚本,这次的脚本也是匆匆写的,还有很多可优化点,感兴趣的可以参考自己优化下,写的不完善地方也希望指 ...
- 从0开始学Git——Git的常用配置
配置user信息 配置user.name和user.email git config --global user.name 'admin' #设置用户名 git config --global use ...
- 第二章、 Vue 起步
2-2.编写hello world 首先创建vue实例,然后实例接收一些配置项,el表示实例负责管理的区域,data表示区域内的数据 两秒后内容变为bye world 其中app表示实例对象,$dat ...
- 2020ubuntu1804server编译安装redis笔记(一)及报make test错误解决办法
redis的大名我想大家都不陌生,今天在ubuntu server上进行编译安装,虽然apt也可以安装,但作为内存数据库,redis又是c开发的,编译安装,对机器的适应和性能更好. 安装笔记如下 第1 ...
- django数据库分库migrate
最近在研究微服务和分布式,设计到了数据库分库,记录一下 首先,创建多个数据库,如果是已经生成的数据库,可以分库,这里我是新创建的项目,刚好可以用来尝试 我是用docker创建的mysql数据库容器 拉 ...
- 设计模式之委派模式,大名鼎鼎的Spring都在用
什么是委派模式 虽然说委派模式不属于Gof23中设计模式,但这并不影响它成为一种经典的设计模式. "委派"字面意思就是指派一件事情给某人.类比到生活中的场景,比如项目leader指 ...
- ReentrantReadWriteLock 源码分析以及 AQS 共享锁 (二)
前言 上一篇讲解了 AQS 的独占锁部分(参看:ReentrantLock 源码分析以及 AQS (一)),这一篇将介绍 AQS 的共享锁,以及基于共享锁实现读写锁分离的 ReentrantReadW ...
- Linux系统之LNMP及nginx反向代理实现
1.编译安装LNMP,并安装wordpress 首先准备环境,编译安装LNMP可以是多台主机,也可以是单台主机,把nginx,mysql,php都集中安装在一个主机上:我这里以一台主机为例吧!! 一. ...
- USB概述及协议基础
USB概述及协议基础 USB的拓扑结构 USB是一种主从结构的系统.主机叫做Host,从机叫做Device(也叫做设备). 通常所说的主机具有一个或者多个USB主控制器(host controller ...
- Gorm 预加载及输出处理(二)- 查询输出处理
上一篇<Gorm 预加载及输出处理(一)- 预加载应用>中留下的三个问题: 如何自定义输出结构,只输出指定字段? 如何自定义字段名,并去掉空值字段? 如何自定义时间格式? 这一篇先解决前两 ...