Pod::Spec.new do |s|
s.name = 'AKProtoOC'
s.version = '1.0.0'
s.license = 'MIT'
s.summary = 'PB文件本地库管理'
s.homepage = 'https://xxxxxx'
s.author = { 'CoderWGB' => 'xxx' }
s.source = { :file => './AKProtoOC', :tag => "v#{s.version}" }
s.requires_arc = false #pod私库的好处 不用自己添加mrc兼容 其次新增或者修改只需要把文件放进来 `pod install`就好了
s.ios.deployment_target = '10.0'
# s.source_files = 'AKProtoOC/**/*.{h,m}'
# s.public_header_files = 'AKProtoOC/**/*.h'
s.dependency 'Protobuf', '~> 3.6.1'
s.subspec 'client' do | ss |
ss.source_files = 'AKProtoOC/client/*.{h,m}'
end
s.subspec 'pb' do | ss |
ss.source_files = 'AKProtoOC/pb/*.{h,m}'
end
s.subspec 'plugin_pb' do | ss |
ss.source_files = 'AKProtoOC/plugin_pb/*.{h,m}'
end
s.subspec 'uauth_pb' do | ss |
ss.source_files = 'AKProtoOC/uauth_pb/*.{h,m}'
end
end
pod install
之后发现还是报错,有些可能是后端文件依赖规则没写好,导致生成的枚举一些定义重复,这个需要手动改- 生成的
OC
代码路径为相对路径#import "pb/CommonExt.pbobjc.h"
类似这种, 本地pod
管理之后貌似只能#import "CommonExt.pbobjc.h"
这样导入
所以让GPT
写了个脚本,执行拉取pb
并生成OC
文件之后,再执行py
脚本改改头文件导入
import os
def process_file(file_path):
with open(file_path, 'r') as f:
lines = f.readlines()
with open(file_path, 'w') as f:
for line in lines:
if line.startswith('#import "') and '/' in line:
parts = line.split('/')
last_part = parts[-1].strip()
new_line = '#import "{}"\n'.format(last_part)
f.write(new_line)
else:
f.write(line)
def process_directory(dir_path):
for root, dirs, files in os.walk(dir_path):
for file in files:
if file.endswith('.h') or file.endswith('.m'):
file_path = os.path.join(root, file)
process_file(file_path)
if __name__ == '__main__':
process_directory('.')
如此就搞定了, 写py
脚本这件事情上 GPT
还算靠谱~