需要借助milend的hmap工具[https://github.com/milend/hmap]
Homebrew 安装hmap brew install milend/taps/hmap
#!/usr/bin/ruby
require 'json'
# 定义脚本运行路径,将在此路径查找.h文件
directory_path = Dir.pwd()
# json 文件生成路径
json_file_path = ""
# hmap文件生成路径
hmap_file_path = ""
json_arr = Hash[]
h_arr = Dir.glob("#{directory_path}/**/*.h")
h_arr.each do |f|
file_arr = File::split(f)
filename = file_arr[1]
suffix = filename
prefix = file_arr[0]
json_arr[filename] = Hash["prefix" => "#{prefix}/", "suffix" => suffix]
# 如果是pod路径,添加path/a.h这样的引用,如SDWebImage/NSImage+Compatibility.h
path_arr = f.split("/")
privatePods_index = path_arr.index("Pods")
if privatePods_index
filename = path_arr[privatePods_index+1] + "/" + filename
json_arr[filename] = Hash["prefix" => "#{prefix}/", "suffix" => suffix]
end
end
# 写入json文件
File.open(json_file_path, "w+") do |aFile|
aFile.syswrite(json_arr.to_json)
end
# 调用hmap将json转为hmap
shell = "hmap convert #{json_file_path} #{hmap_file_path}"
%x(#{shell})
puts "Success!"
生成之后在工程中设置HEADER_SEARCH_PATHS 为上面生成的hmap路径
并且将USE_HEADERMAP设为NO
网友评论