一、主工程Project
1)创建 App Project
2)添加CocoaPods的Podfile文件
source 'https://github.com/CocoaPods/Specs.git'
platform:ios,'10.0'
workspace 'WorkSpaceDemo'
def commonPods
pod 'AFNetworking', '~> 4.0.1'
pod 'YYKit','~> 1.0.9'
pod 'MJExtension', '~> 3.1.0'
end
target "WorkSpaceDemo" do
project './WorkSpaceDemo/WorkSpaceDemo.xcodeproj'
commonPods
pod 'SDWebImage'
end
3)cd 到 Podfile 所在目录,pod install 实现工程的pod依赖
pod install --no-repo-update
二、模块/子工程Project
1)创建 Framework Project(Framework / Static Library / App)
2)Build Setting中 mach-o type 由Dynamic Library改为 Static Library,使用静态库构建mach-o
3)在Framework Project中提供给外部使用的能力,类头文件的 Target Membership 设置为Public,否则在外部引用会报错
4)选择Framework Target对应的Scheme,Build - Any iOS Device 构建静态Framework;
5)导入主工程中,Embed保持默认(Do Not Embed)
6)添加Framework Target的pod配置,并pod install 实现相应的pod依赖
target "FlowerKit" do
project './FlowerKit/FlowerKit.xcodeproj'
commonPods
pod 'SSZipArchive'
end
target "LeavesKit" do
project './LeavesKit/LeavesKit.xcodeproj'
commonPods
pod 'SDWebImage'
end
target "FruitKit" do
project './FruitKit/FruitKit.xcodeproj'
commonPods
end
7)工程目录分布
三、API的调用
1)在Framework对应的 .h文件中添加提供给外部使用的类声明
#import <Foundation/Foundation.h>
#import <FlowerKit/FlowerAPITest.h>
#import <FlowerKit/FlowerUtils.h>
//! Project version number for FlowerKit.
FOUNDATION_EXPORT double FlowerKitVersionNumber;
//! Project version string for FlowerKit.
FOUNDATION_EXPORT const unsigned char FlowerKitVersionString[];
2)在工程中引入Framework对应的 .h文件声明,实现具体API的调用
#import "AppDelgate.h"
#import <FlowerKit/FlowerKit.h>
@implementation AppDelgate
- (void)test {
FlowerAPITest *apiTest = [FlowerAPITest new];
[apiTest test];
}
@end