Since the company’s project is too old, MRC is still used for memory management, resulting in a lot of problems. Recently, we started to transform the project from MRC to ARC. I have two preliminary ideas for implementation:
I. The first scheme (One-step)
1. Filter files that do not need to be converted (files that do not need to be converted need to be counted and marked by the third party)
- Do not want to convert files to add
-fno-objc-arc
Mark; - Replace arc versions of third-party libraries, if any, and add none
-fno-objc-arc
Mark;
2. Use Xcode’s built-in conversion tool for conversion
- Xcode – > Edit – > Convert – > To Objective – C ARC;
- If you complete the operations in step 1, you can select all of them here.
- Files not selected here will be automatically added after automatic conversion
-fno-objc-arc
The tag;
Note: The yellow exclamation mark on the class here is because the -fobjC-arc tag was used in the project. If a third party uses [self retain] during the automatic conversion process, this clause will be deleted directly during the conversion. This will cause the class that originally relied on this clause to be released after initialization, which will cause the wild pointer. Therefore, try to add the flag for the third party library that uses MRC.
Fix Error and WARN
- Error needs to be resolved;
- Warn can be resolved as much as possible, and some irrelevant warn can be masked by setting items.
Ii. The second method (Step by step)
1. Turn on ARC switch
- Build SettingsObjective -c Automatic Reference Counting YES;
2. Remove all previous ARC files-fobjc-arc
The tag;
3. Add to all MRC code-fno-objc-arc
Mark;
Note: In view of the workload problem in step 2 and step 3, it is recommended to use scripts to handle it here, and then gradually change the MRC file to arc file in the subsequent development process, and delete the -fno-objC-ARC mark.
The implementation of the first method will be described in more detail later (to be continued)