新建工程 -> MyTestLibraryProduct,或者在你已有项目中进行如下操作:
右键 -> New Group -> Dependencies

在此目录下File -> New -> Product -> iOS -> Cocoa Touch Static Library,


接下来,可以参考文章对静态库进行配置,然后添加依赖,选中 MyTestLibraryProduct,在
TARGETS 中选中MyTestLibrary,在 Build Phases 的 Target Dependencies 中添加 MyTestLibrary:


此时点击Run,MyTestLibrary 的 Products 下的 libMyTestLibrary.a 变成已存在状态,

使用静态库的文件,在Hello中新增对外的方法:


选中 MyTestLibraryProduct,TARGETS 下选中 MyTestLibraryProduct,在 Build Settings 下面搜索 header search paths ,添加 ../MyTestLibrary/MyTestLibrary,

在 ViewController.m 中实现以下方法:

点击Run,运行成功。
为静态库添加Bundle:
在 MyTestLibraryProduct 工程中选中 MyTestLibrary 子工程,点击 Add Target按钮,导航到macOS->Framework & Library->Bundle,将新的Bundle命名为 MyTestLibraryBundle,如下图:


这里需要配置几个编译设置,因为你正在创建一个在iOS上使用的bundle,这与默认的macOS不同。选择 MyTestLibraryBundle 目标,然后点击 Build Settings 边栏,搜搜 base sdk,选择Base SDK这一行,按下delete键,这一步将macOS切换为iOS。

默认情况下,当你导入一个retina@2x的图片是,普通版和Retina版的将会合并成一个多resolution的TIFF(标签图像文件格式,Tagged Image File Format)。为了避免出现这种情况,将 COMBINE_HIDPI_IMAGES 设置为NO。

为了确保bundle也能被编译,选择 MyTestLibrary 目标,选择 Build Phases 边栏,展开 Target Dependencies 面板,点击 + 按钮,选择 MyTestLibraryBundle 目标将其添加为依赖。

网友评论