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
還算靠譜~