项目虽然是swift 项目,但是依然可以使用DoKit 集成工具来排查内存泄漏bug. 采用pod 引入:
pod 'DoraemonKit/Core', '~> 3.0.4', :configurations => ['Debug']
pod 'DoraemonKit/WithMLeaksFinder', '~> 3.0.4', :configurations => ['Debug']
原因是这个类DoraemonHomeViewController 有崩溃,由于是pod 引入,又是涉及到多人开发,所以不能直接修改框架源码,只能在podfile中添加ruby脚本来修复;
解决办法: 在podfile中添加如下脚本
def find_and_replace(file_path, find_text, replace_text)
text = File.read(file_path)
unless text.include?(replace_text)
new_contents = text.gsub(find_text, replace_text)
File.open(file_path, "w") { |f| f.puts new_contents }
end
end
file_path = "Pods/DoraemonKit/iOS/DoraemonKit/Src/Core/Entry/Home/DoraemonHomeViewController.m"
find_text = "- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {\n DoraemonHomeCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:DoraemonHomeCellID forIndexPath:indexPath];\n NSInteger row = indexPath.row;\n NSInteger section = indexPath.section;\n \n if (section < _dataArray.count) {"
replacement_text = "- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {\n NSInteger row = indexPath.row;\n NSInteger section = indexPath.section;\n \n if (section < _dataArray.count) {\n DoraemonHomeCell *cell = [self.collectionView dequeueReusableCellWithReuseIdentifier:DoraemonHomeCellID forIndexPath:indexPath];"
find_and_replace(file_path, find_text, replacement_text)