2016-08-23 25 views
9

OS的使用:Ubuntu的16.04錯誤:無法解析的標識符 '過程'

斯威夫特版本:3.0預覽版6

我按照這個getting started page

greeter.swift

func sayHello(name: String) { 
    print("Hello, \(name)!") 
} 

main.swift

if Process.arguments.count != 2 { 
    print("Usage: hello NAME") 
} else { 
    let name = Process.arguments[1] 
    SayHello(name: name) 
} 

錯誤我收到

$ swift build 
Compile Swift Module 'myapp' (2 sources) 
/Sources/main.swift:1:4: error: use of unresolved identifier 'Process' 
if Process.arguments.count != 2 { 
    ^~~~~~~ 
/Sources/main.swift:4:16: error: use of unresolved identifier 'Process' 
    let name = Process.arguments[1] 
       ^~~~~~~ 
<unknown>:0: error: build had 1 command failures 
error: exit(1): swift/bin/swift-build-tool -f .build/debug.yaml 

回答

19

工藝改爲的CommandLine在SWIFT 3.0

嘗試用CommandLine


這裏更換Process是鏈接到該改變了它的承諾: Rename Process to CommandLine [SE-0086].

+0

CommandLine是GitHu中的一個項目b而不是Swift核心庫的一部分。 https://github.com/jatoben/CommandLine –

+0

這工作!謝謝。 – ECMAScript

+5

@ChristianAbella:'CommandLine'是核心Swift 3的一部分:https://github.com/apple/swift/blob/master/stdlib/public/core/CommandLine.swift。另見https://github.com/jatoben/CommandLine/issues/77。 –

相關問題