创建一个Appliction工程–SDKTestDemo
在已创建好工程中创建静态库的Target-SDKplugin
创建成功后
点击SDKTestDemo.xcodepro 即可看到 SDKTestDemo 和 SDKplugin 如下
设置静态库对外可见的.h文件
点击Target- SDKplugin
设置静态库 与 工程的依赖关系
点击Target - SDKTestDemo
因为静态库中不能有资源文件,创建bundle资源库专门存放静态库的资源文件-SDKBunld
1.创建.Bundle文件:new Target -->选中MacOS选项--->创建bundle
2.修改bundle资源库的配置
修改前:
修改后:
设置Bundle资源库 与 工程的依赖关系
点击Target - SDKTestDemo
注意事项
- 当在静态库中加载bundle的Xib文件时,会报
Unknown class VCCardViewCell in Interface Builder file.
2018-08-02 09:05:48.070615+0800 HisunVisitingCardDemo[18443:9501864] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x10343c730> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key headerImageView.
解决方案:在Build-setting -> Other Linker Flags ->-ObjC,即可
- 静态库中加载Xib,图片资源
#define HISUNPLUGIN_BUNDLE_NAME @"HisunVisitCardBundle.bundle"
#define HISUNPLUGIN_BUNDLE_PATH [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent: HISUNPLUGIN_BUNDLE_NAME]
#define HISUNPLUGIN_MYBUNDLE [NSBundle bundleWithPath: HISUNPLUGIN_BUNDLE_PATH]
[[HISUNPLUGIN_MYBUNDLE loadNibNamed:_cardNib owner: self options:nil] lastObject]
[[UIImage imageNamed:[NSString stringWithFormat:@"%@/%@.png", HISUNPLUGIN_BUNDLE_PATH, pic]]