swifter-tips / Public-Issues

Public issues for Swifter-tips book
103 stars 3 forks source link

swift 命令行工具 error #53

Closed zyg-github closed 9 years ago

zyg-github commented 9 years ago

代码如下: class MyClass { let name = "XiaoMing" func hello() { print("Hello (name)") } } let object = MyClass() object.hello()

在xcode 是运行成功的 在命令行有错 错误:

onevcat commented 9 years ago

这里 MyClass.swift 和 main.swift 是两个不同的输入文件,命令行 swiftc 后面直接跟的都是输入文件。

zyg-github commented 9 years ago

哦哦 我晕 是我错了 有劳了 还有个问题 ./MyClass.swift 为什么报错 难道我没有引入什么吗?

onevcat commented 9 years ago

直接当脚本运行的话需要指定 swift 命令行位置,完整的应该是这样的

#!/usr/bin/env swift
print("hello")
// Terminal
> chmod 755 hello.swift
> ./hello.swift

// 输出:
hello
zyg-github commented 9 years ago

好的 谢谢 喵神