Xcode 游乐场不执行功能
Xcode playground not executing functions
我创建了一个新的游乐场并添加了简单的功能,但该功能从未被调用过:
var str = "New playground"
func hello()
{
print("Hello, World")
}
你们知道为什么函数没有被调用吗?
非常感谢你的帮助
因为你没有调用函数。只需调用它:
func hello()
{
print("Hello, World")
}
hello()
此外,如果您在方法实现之前调用该方法,Swift Playground 将不允许您这样做,并且会出现如下错误
Use of unresolved identifier 'hello'
错误的顺序:
hello()
func hello()
{
print("Hello, World")
}
正确的顺序
func hello()
{
print("Hello, World")
}
hello()
我创建了一个新的游乐场并添加了简单的功能,但该功能从未被调用过:
var str = "New playground"
func hello()
{
print("Hello, World")
}
你们知道为什么函数没有被调用吗?
非常感谢你的帮助
因为你没有调用函数。只需调用它:
func hello()
{
print("Hello, World")
}
hello()
此外,如果您在方法实现之前调用该方法,Swift Playground 将不允许您这样做,并且会出现如下错误
Use of unresolved identifier 'hello'
错误的顺序:
hello()
func hello()
{
print("Hello, World")
}
正确的顺序
func hello()
{
print("Hello, World")
}
hello()