StrongSelfRewriter is the tool to replace variable name for guard let self = self
optional binding code using SwiftSyntax
StrongSelfRewriter Sample.swift
Result
func execute(completion: () -> Void) {
DispatchQueue.main.async { [weak self] in
- guard let strongSelf = self else {
+ guard let self = self else {
return
}
- strongSelf.output(text: "hello")
- print(strongSelf)
+ self.output(text: "hello")
+ print(self)
}
}
Options
$ StrongSelfRewriter
OVERVIEW: Replace optional self binding variable name to "self" or specified name by --rewrite option
USAGE: StrongSelfRewriter <path>
OPTIONS:
--dryrun, -d Display rewrited code simply
--dump Dump syntax tree
--rewrite Variable name for replacement. Default is self
--help Display available options
POSITIONAL ARGUMENTS:
path Path to .swift file
git clone <repo>
cd <repo>
swift build
Debug run
.build/debug/StrongSelfRewriter rewrite Tests/StrongSelfRewriterTests/Sample.swift
Generate Xcode project
swift package generate-xcodeproj
Release build
swift build -c release
link |
Stars: 13 |
Last commit: 5 years ago |
First release
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics