{"id":15038100,"url":"https://github.com/luizzak/swiftrewriter","last_synced_at":"2025-04-12T16:35:49.963Z","repository":{"id":41370988,"uuid":"140700310","full_name":"LuizZak/SwiftRewriter","owner":"LuizZak","description":"A Swift Package Manager console app and library to convert Objective-C code into Swift.","archived":false,"fork":false,"pushed_at":"2025-02-12T13:44:23.000Z","size":10572,"stargazers_count":269,"open_issues_count":3,"forks_count":42,"subscribers_count":15,"default_branch":"master","last_synced_at":"2025-04-03T17:12:34.598Z","etag":null,"topics":["conversion","objc-to-swift","objc2swift","objective-c","source-to-source","swift","swift4","transpiler"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/LuizZak.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-12T10:48:12.000Z","updated_at":"2025-03-27T03:45:21.000Z","dependencies_parsed_at":"2024-06-14T22:39:32.525Z","dependency_job_id":"4dc2c83b-5ece-4a49-a7ce-056c39c8c285","html_url":"https://github.com/LuizZak/SwiftRewriter","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuizZak%2FSwiftRewriter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuizZak%2FSwiftRewriter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuizZak%2FSwiftRewriter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/LuizZak%2FSwiftRewriter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/LuizZak","download_url":"https://codeload.github.com/LuizZak/SwiftRewriter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248597236,"owners_count":21130840,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["conversion","objc-to-swift","objc2swift","objective-c","source-to-source","swift","swift4","transpiler"],"created_at":"2024-09-24T20:37:06.682Z","updated_at":"2025-04-12T16:35:49.936Z","avatar_url":"https://github.com/LuizZak.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftRewriter\n\n| Platform | Build Status |\n|----------|--------|\n| macOS    | [![Build Status](https://dev.azure.com/luiz-fs/SwiftRewriter/_apis/build/status/LuizZak.SwiftRewriter?branchName=master\u0026jobName=macOS)](https://dev.azure.com/luiz-fs/SwiftRewriter/_build/latest?definitionId=3\u0026branchName=master) |\n| Linux    | [![Build Status](https://dev.azure.com/luiz-fs/SwiftRewriter/_apis/build/status/LuizZak.SwiftRewriter?branchName=master\u0026jobName=Linux)](https://dev.azure.com/luiz-fs/SwiftRewriter/_build/latest?definitionId=3\u0026branchName=master) |\n\n[![codecov](https://codecov.io/gh/LuizZak/SwiftRewriter/branch/master/graph/badge.svg?token=xoSZNXwFLG)](https://codecov.io/gh/LuizZak/SwiftRewriter)\n\nA source-to-source compiler for expediting Objective-C-to-Swift source conversion.\n\nFor information about how it's structured, see the [Architecture](Architecture.md) page.\n\n#### Example\n\nGiven the following files:\n\nMyClass.h:\n```objc\n/// A simple class to store names\n@interface MyClass : NSObject\n/// First name\n@property (nonnull) NSString *name;\n/// Last name\n@property (nonnull) NSString *surname;\n\n- (nonnull instancetype)initWithName:(nonnull NSString*)name surname:(nonnull NSString*)surname;\n/// Prints the full name to the standard output\n- (void)printMyName;\n@end\n```\n\nMyClass.m:\n```objc\n@implementation MyClass\n- (instancetype)initWithName:(NSString*)name surname:(NSString*)surname {\n    self = [super init];\n    if(self) {\n        self.name = name;\n        self.surname = surname;\n    }\n    return self;\n}\n- (void)printMyName {\n    NSLog(@\"%@ %@\", self.name, self.surname);\n}\n@end\n```\n\nRunning SwiftRewriter as shown:\n\n```bash\n$ swift run SwiftRewriter files --colorize --target stdout MyClass.h MyClass.m\n```\n\nwill produce the following Swift file in the standard output:\n\n```swift\n/// A simple class to store names\nclass MyClass: NSObject {\n    /// First name\n    var name: String\n    /// Last name\n    var surname: String\n\n    init(name: String, surname: String) {\n        self.name = name\n        self.surname = surname\n        super.init()\n    }\n\n    /// Prints the full name to the standard output\n    func printMyName() {\n        NSLog(\"%@ %@\", self.name, self.surname)\n    }\n}\n```\n\n#### Requirements\n\nSwift 6.0\n\n#### Usage\n\n- From the working directory execute as follows:\n\n```bash\n$ swift run -c=release SwiftRewriter files --colorize --target stdout /path/to/MyClass.h /path/to/MyClass.m\n```\n\n- To convert a directory containing Objective-C files (recursively), saving resulting .swift files to disk, execute as follows:\n\n```bash\n$ swift run -c=release SwiftRewriter path /path/to/project/\n```\n\n- Run `swift run SwiftRewriter --help` to print the full reference of command line arguments SwiftRewriter accepts. Reference also available bellow (for `path` subcommand):\n\nUsage:\n\n```\nOVERVIEW: \nMain frontend API for SwiftRewriter. Allows selection of specific source language modes.\n\nUSAGE: SwiftRewriter \u003csubcommand\u003e\n\nOPTIONS:\n  -h, --help              Show help information.\n\nSUBCOMMANDS:\n  objc (default)          Objective-C code conversion frontend\n\n  See 'SwiftRewriter help \u003csubcommand\u003e' for detailed help.\n```\n\nObjective-C frontend command arguments:\n\n`\u003e swift run SwiftRewriter objc path --help`\n\n```\nOVERVIEW: \n\nExamines a path and collects all .h/.m files to convert, before presenting a prompt to confirm conversion of files.\n\nUSAGE: SwiftRewriter path \u003coptions\u003e\n\nARGUMENTS:\n  \u003cpath\u003e                  Path to the project to inspect \n\nOPTIONS:\n  -e, --exclude-pattern \u003cexclude-pattern\u003e\n                          Provides a file pattern for excluding matches from the initial Objective-C files search. Pattern is applied to the full path. \n  -i, --include-pattern \u003cinclude-pattern\u003e\n                          Provides a pattern for including matches from the initial Objective-C files search. Pattern is applied to the full path. --exclude-pattern takes priority over --include-pattern\n                          matches. \n  -s, --skip-confirm      Skips asking for confirmation prior to parsing. \n  -o, --overwrite         Overwrites any .swift file with a matching output name on the target path. \n  -c, --colorize          Pass this parameter as true to enable terminal colorization during output. \n  -e, --print-expression-types\n                          Prints the type of each top-level resolved expression statement found in function bodies. \n  -p, --print-tracing-history\n                          Prints extra information before each declaration and member about the inner logical decisions of intention passes as they change the structure of declarations. \n  -v, --verbose           Prints progress information to the console while performing a transpiling job. \n  -t, --num-threads \u003cnum-threads\u003e\n                          Specifies the number of threads to use when performing parsing, as well as intention and expression passes. If not specified, thread allocation is defined by the system\n                          depending on usage conditions. \n  --force-ll              Forces ANTLR parsing to use LL prediction context, instead of making an attempt at SLL first. May be more performant in some circumstances depending on complexity of original\n                          source code. \n  --emit-objc-compatibility\n                          Emits '@objc' attributes on definitions, and emits NSObject subclass and NSObjectProtocol conformance on protocols.\n\n                          This forces Swift to create Objective-C-compatible subclassing structures\n                          which may increase compatibility with previous Obj-C code. \n  --diagnose-file \u003cdiagnose-file\u003e\n                          Provides a target file path to diagnose during rewriting.\nAfter each intention pass and after expression passes, the file is written\n                          to the standard output for diagnosing rewriting issues. \n  -w, --target \u003ctarget\u003e   Specifies the output target for the conversion.\nDefaults to 'filedisk' if not provided.\n\n    stdout\n        Prints the conversion results to the terminal's standard output;\n    \n                              filedisk\n                                  Saves output of conversion to the filedisk as .swift files on the same folder as the input files. \n  -f, --follow-imports    Follows #import declarations in files in order to parse other relevant files. \n  -h, --help              Show help information.\n```\n\nThe program should output the contents of the files you pass into the standard output.\n\n#### Project goals\n\nThis is mostly a side project of mine to train my Swift and architecture chops. That being said, there are a couple of main goals that I have in mind going forward with this:\n\nSwiftRewriter should:\n\n1. Always produce valid Swift syntax as output (not necessarily _semantically_ valid, though);\n2. Try to produce code that functions as close as possible to the original Objective-C source, with no surprises;\n3. Try to do as much as possible of the tedious laborious work of converting syntax and getting it ready for the user to make the last manual changes that will inevitably be necessary;\n4. Whenever possible, make automatic, semantically correct transformations that will save the user some time from doing it manually later;\n5. Be extensible, as far as writing a new syntax/type-structure transformation pass is concerned. (for more info on transformation passes, see aforementioned [Architecture document page](Architecture.md))\n\nSome other libraries and resources that are also concerned with automating the process of converting Objective-C to Swift to some degree include that I think are worth mentioning:\n\n- [Yahoo's Objc2Swift](https://github.com/yahoojapan/objc2swift) makes language transformations, but it has shortcomings as far as making large transpilations go: Its grammar implementation lacks modern Objective-C features (such as generic types), and it makes no semantic transformations, doing AST conversions only. Main inspiration for writing this tool, I just thought augmenting it with a more modern Objective-C syntax and some semantical awareness would be nifty.\n\n- [Objc2Swift.js](http://okaxaki.github.io/objc2swift/index.html) is a more fully-fledged, nifty converter that is semantically-aware and attempts to produce working code while respecting semantics, but it does not currently support emitting Swift 3, 4 and 5-compatible code.\n\n- [Swiftify](https://objectivec2swift.com/) is a comercial product which does many high and low-level transformations, producing code that appears to be (I haven't tested it much, tbh) nearly fully-functioning Swift code.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizzak%2Fswiftrewriter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluizzak%2Fswiftrewriter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluizzak%2Fswiftrewriter/lists"}