1.创建TestDemo工程, 选择iOS -> Single View App
2.创建TestSDK工程, 选择iOS -> Framework
修改Build Setting -> All -> Mach-O Type 为Static Library
修改iOS Deployment Target
修改Targeted Device Family 为 iPhone
选中Generic iOS Device, 编译
3.创建TestSDKSource工程, 选择macOS -> Bundle
修改Build Setting -> All -> Base SDK 为iOS
修改iOS Deployment Target
修改Targeted Device Family 为 iPhone
选中Generic iOS Device, 编译
4.创建Workspace
在左侧栏右键->Add Files to “xxxDemo”
将1.2.3步骤创建的.xcodeproj的文件添加进workspace
5.用TestDemo.xcworkspace打开工程
修改左上角Scheme为TestDemo
添加General -> Frameworks, -> +
添加TestSDK.framework
添加TestSDKSource.bundle
引用头文件#import <TestSDK/TestSDK.h>
检查Demo的BuildPhases下的Copy Bundle Resources下是否添加了TestSDKSource.bundle,若没有则需要手动添加,否则将无法找到该bundle
6.在TestSDK添加类
如需要公开某个类可以在外部使用, 请修改TestSDK->Build Phases -> Headers -> Public, 将某个类放入Public下面, 然后再在TestSDK.h头文件中引入#import <TestSDK/XXX.h>
添加或修改文件后需要修改左上角Scheme为TestSDK, 编译
如需在TestSDK加载TestSDKSource.bundle中的xib, 需先找到bundle, 前提是已经在TestDemo中添加了bundle
NSBundle *bundle = [NSBundle bundleWithPath:[[NSBundle mainBundle] pathForResource:@"TestSDKSource" ofType:@"bundle"]];
UIView *view = [[bundle loadNibNamed:@"View" owner:nil options:nil] objectAtIndex:0];
如需在TestSDK加载TestSDKSource.bundle中的图片,inDirectory参数为图片所在的文件夹
NSString *imgStr = [bundle pathForResource:@"image1" ofType:@"png" inDirectory:@"images"];
UIImage *image = [UIImage imageWithContentsOfFile:imgStr];
网友评论