I'm using protobuf to generate swift classes from protofiles (I've written a script for this purpose). Now I need to add all generated files into target in Xcode project.
How can I do this programmatically? Maybe script in Build Phases or some other kind of actions in macOS (Automator?)?
CocoaPods uses this project to modify project files: https://github.com/CocoaPods/Xcodeproj
It is possible to do that with functionality built into Xcode (we have done it with c++, but it should be possible with swift, too):
In your target, add a custom shell script build rule that matches the extension of your protofiles.
Call your script using "${INPUT_FILE_PATH}"
and "${SCRIPT_OUTPUT_FILE_0}"
.
If the output file's extension matches another build rule, that one will be executed. So in you case, set the output file of the build rule to ${DERIVED_FILE_DIR}/${INPUT_FILE_BASE}.swift
in order to send it to the swift compiler.
Now go to your target's Compile Sources build phase and add the protofiles.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With