Cyr*_*lle 16
而不是将它们标记为
//TODO: do something
Run Code Online (Sandbox Code Playgroud)
我喜欢这样写:
#warning TODO do something
Run Code Online (Sandbox Code Playgroud)
这允许在问题导航器中查看它们.在生产版本中,我甚至可以检查"将所有警告视为错误"编译器设置.
Geo*_*ews 10
您可以向目标添加"运行脚本"构建阶段,该阶段将查看整个项目的TODO:| FIXME:标记并将其标记为警告.
每当您构建项目%+ B时,这个新的构建阶段将在问题导航器中将所有TODO标记列为警告.
这里有Ben Dodson的Swift文件教程链接:https://bendodson.com/weblog/2014/10/02/showing-todo-as-warning-in-swift-xcode-project/
以下是我一直在研究的项目的截图:
除了使用快捷键“Command + Shift + F”进行全局搜索并查找所有出现的 TODO 和 FIXME 之外,您还可以将所有 TODO 和 FIXME 转换为警告:
导航到 Build Phases,单击左上角的 +,然后选择“New Run Script Phase”
在文本区域中输入以下内容:
TAGS="TODO:|FIXME:"
find "${SRCROOT}/" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/"
Run Code Online (Sandbox Code Playgroud)
保留所有其他选项,然后构建您的项目。
享受!
如果除了 MARK FIXME TODO 之外,你还想要自己的,你可以制作第 4 个我们称之为 ERROR 的,它将像任何其他实际错误一样将你的行高亮显示为红色,但不会使你的应用程序崩溃:
TAGS="TODO:|FIXME:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
Run Code Online (Sandbox Code Playgroud)
如果您不希望脚本显示与 cocoapods 一起安装的软件包中存在的 TODO 和 FIXME,请使用此修改后的脚本(仍包含上面的 ERROR 标记):
TAGS="TODO:|FIXME:"
ERRORTAG="ERROR:"
find "${SRCROOT}" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -not -path "${SRCROOT}/Pods/*" -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
Run Code Online (Sandbox Code Playgroud)
如果您在使用 cocoapods 之外安装软件包(例如手动执行或使用 Swift Package Manager),那么您可以通过在路径中输入您的项目名称,让脚本忽略工作区中除项目之外的所有内容,因此如果您的项目被称为“MyProject”,然后在脚本find "${SRCROOT}"中用 find替换,"${SRCROOT}/MyProject"所以最终将是(再次包括我们的 ERROR 标签):
TAGS="TODO:|FIXME:"
ERRORTAG="ERROR:"
find "${SRCROOT}/MyProject" \( -name "*.h" -or -name "*.m" -or -name "*.swift" \) -print0 | xargs -0 egrep --with-filename --line-number --only-matching "($TAGS).*\$|($ERRORTAG).*\$" | perl -p -e "s/($TAGS)/ warning: \$1/" | perl -p -e "s/($ERRORTAG)/ error: \$1/"
Run Code Online (Sandbox Code Playgroud)
归功于Hector Matos、Zoe Van Brunt 和 Noah Wilder,来自How to Highlight Your TODOS、FIXMES 和 Xcode 中的错误
| 归档时间: |
|
| 查看次数: |
5257 次 |
| 最近记录: |