需要借助milend的hmap工具[https://github.com/milend/hmap]
Homebrew 安裝hmap brew install milend/taps/hmap
#!/usr/bin/ruby
require 'json'
# 定義腳本運(yùn)行路徑,將在此路徑查找.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
# 調(diào)用hmap將json轉(zhuǎn)為hmap
shell = "hmap convert #{json_file_path} #{hmap_file_path}"
%x(#{shell})
puts "Success!"
生成之后在工程中設(shè)置HEADER_SEARCH_PATHS 為上面生成的hmap路徑
并且將USE_HEADERMAP設(shè)為NO