SwiftGen is a tool to convert TypeScript files into Swift code.
To install the package, run:
npm install -g swiftgenCreate a config.json file in your project directory. Example configuration:
{
"inputDir": "path/to/ts-files/root/dir",
"outputDir": "path/to/output/dir",
"outputPrefix": "",
"outputSuffix": ".swift",
"outputFileName": "TypeSwift",
"debug": false
}inputDir: Path to TypeScript files that will be converted to Swift. The search is recursive.outputDir: Path to export the generated Swift file. It will replace any existing files with the same name and path.
If you want to use a custom configuration file, run SwiftGen with the following command:
swiftgen --config path/to/config.jsonIf no configuration file is specified, SwiftGen will use the default config.json located in the config directory.
-
Create a
config.jsonfile in your project directory with the desired configuration. -
Run the tool:
swiftgen --config /path/to/config.jsonOr, if the config.json file is in your project root, simply:
swiftgenCompatible with both relative and absolute paths.
If you have installed SwiftGen globally and want to update it to the latest version, run:
npm update -g swiftgenAlternatively, you can uninstall and reinstall the package:
npm uninstall -g swiftgen
npm install -g swiftgenFor more details, refer to the TypeSwift project on GitHub.