How do I transfer to Swift for an old Objective-C project
Create a new Swift project and delete the Storyboard file.
Then copy the Storyboard file of the Objective-C project, copy the.h and.m files (usually not appdelegate.h /.m), and put it in the new project
Copy-and-paste method is good, the code level is less involved
In the Swift project, when you use objective-C code, you use a bridge file
I’m also going to reference all the.h files and import them.
Replication is trivial
How to copy efficiently?
Script method is good
find . -type f -name '*.h' -exec bash -c ' for result; do got=${result:2} printf "#import \"%q\"\n" "$got" done ' _ {} + | sort -n
Copy the code
You can copy it all at once
A brief explanation of the script:
find . -type f -name '*.h'
Copy the code
The text I found looks something like this
./AudioEngine.h
./InstrumentViewController.h
./MixerViewController.h
Copy the code
The processed text looks like this
#import "AudioEngine.h"
#import "AudioEngineViewController.h"
#import "AudioViewController.h"
Copy the code
Work with the source code later
Swift version upgrade tips,
Switch the Swift version number and follow the instructions all the way. It’s good
If rewritten, the long-ago, unsupported Swift project is relatively slower