我正在尝试设置合适的shebang来为iOS执行Swift脚本
#!/usr/bin/env xcrun --sdk iphonesimulator swift -target x86_64-apple-ios12.1-simulator
import Foundation
import UIKit
print("Hello, World!")
但是它不起作用。 当我运行脚本时:
./myScript.swift
我在终端机上读到了
<unknown>:0: error: could not load the swift standard library
我一直在尝试不同的shebang设置以使其正常工作
#!/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -sdk /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS12.1.sdk -target x86_64-apple-ios12.1-simulator
,但仍然没有成功。
最后但并非最不重要的一点是,运行iOS版本很重要,因为我需要导入UIKit。
感谢
/// myScript fullversion:
#!/usr/bin/swift
import Foundation
import UIKit
public class FileSystem {
@discardableResult init() {
let fileManager = FileManager.default
do {
let resourceKeys: [URLResourceKey] = [.creationDateKey, .isDirectoryKey]
let documentsURL = fileManager.currentDirectoryPath
guard let enumerator = FileManager.default.enumerator(at: URL(fileURLWithPath: documentsURL),
includingPropertiesForKeys: resourceKeys,
options: [.skipsHiddenFiles], errorHandler: { (url, error) -> Bool in
print("directoryEnumerator error at \(url): ", error)
exit(1)
}) else {
print("error, can't find directory")
exit(1)
}
for case let fileURL as URL in enumerator {
let file = fileURL.lastPathComponent
print(file)
// check if file is a class that conforms to protocol X
}
}
}
}
FileSystem()
./myScript.swift:4:8: error: no such module 'UIKit'