[英]Get the Xcode project directory from the code
Does anyone know how to get a related Xcode project directory right from the code? 有谁知道如何直接从代码中获取相关的Xcode项目目录? I've tried to accomplish it with the pwd
environment, but it only works in Build Phases
> Run Script
. 我尝试使用pwd
环境完成此操作,但是它仅在Build Phases
> Run Script
。
for individual files you can either use the C-macro __FILE__
, or the swift-literal #file
. 对于单个文件,您可以使用C宏__FILE__
或swift-literal #file
。
From the Swift Docs (search for Literal Expressions
on the page) 在Swift Docs中(在页面上搜索Literal Expressions
)
#file
(String) The name of the file in which it appears. #file
(字符串)显示文件的名称。 #line
(Int) The line number on which it appears. #line
(Int)显示它的行号。 #column
(Int) The column number in which it begins. #column
(Int)开头的列号。 #function
(String) The name of the declaration in which it appears. #function
(字符串)出现在其中的声明的名称。 Once you have the path to the file it should be easy to find your way to the project root. 有了文件的路径后,应该很容易找到通往项目根目录的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.