问题
I've running project and its really gigantic, it contain almost 1000 files and 4 Custom (own built) framework and almost 10 others added via Pods. I've gone through Migrating Your Objective-C Code to Swift and also Migrate with Swiftify.
I started to converting each file one by one as Apple suggest but first Conversion isn't successfully done by Swiftify and also dependency issues.
So at this position its looks like that I start walking in Sahara Desert, where I can't see any end point.
So I need some suggestion how to convert to Swift this kinda huge scale project?
回答1:
Your approach of converting Objective-C to Swift is wrong! Apple also took time to adopt Swift completely in their frameworks and the news is in 2018, 85% of the frameworks are converted to Swift, so the point is they has also taken nearly 3 years to get it done!
The biggest problem is that Swift is still evolving and probably next year we might see "Swift 5.0". So what I suggest you to go via following way:
- Pick the latest version of Swift (i.e. 4.2).
- Rather than start converting complete project, adapt modular way.
- From your project, first of all start picking up smaller modules which don't affect app in any way and see that the "Swift" file works well with Objective-C (Your old code). Reference: How can I import Swift code to Objective-C?
- Once you are done with smaller ones, slowly start picking up big modules also you may find open source Swift libraries which are in Objective-C in your project.
- Besides, you can also build modules from scratch in the form of smaller projects and then just drag and drop in Objective-C project.
- Andreas Oetjen Suggestion: You might start by separating the class hierarchy, and convert one "subtree" after the other.
How the above Points help?
- You may find some unusual code or libraries lying around.
- You may end-up having clean code under proper structure
- You can use "Swift + Objective-C" as of now to make your app running smoothly and also giving updates regularly rather than waiting for the months to convert it completely.
回答2:
I recently converted SVProgressHUD to swift using Swiftify. The converted code can be found at here.
The major takeaways would be:
- To start the code conversion one file at a time maintaining interoperability with Objective C, that is the converted swift file should be interoperable with your existing Objective-C code.
- Pick a class which does not have subclasses and is simple.
The detailed conversion strategy can be found here.
回答3:
Objective-C apps can normally be converted to Swift easily. macOS IDE Xcode helps in the smooth migration. Yes, there are some issues, but these can be fixed anyways. Your project is huge, so that can be problem, as so many files are required to be moved. You can try converting files module by module. This way you can divide the migration on file by file basis.
You can check How to Convert an Objective-C IOS App to Swift, the Step by Step Guide for Migration of Objective C apps to Swift.
You have described that you have gone through Migration with Swiftify, so apparently their Objective-C to Swift Converter online tool could not do the job perfectly. You can try Convert Objective-C to Swift Online | iSwift online tool also for Objective C to Swift conversion.
Developers who are new to Swift, can take help from these informative resources.
The Swift Programming Language
Swift - Apple Developer
来源:https://stackoverflow.com/questions/52942575/how-to-convert-giant-project-objective-c-to-swift