传递给不带参数的调用的参数

argument passed to call that takes no argument

我是 Swift 和编码的新手,所以如果这是一个愚蠢的问题,我很抱歉,但是当我测试我的代码时出现了这个错误。 我的代码是:

class Node {
  var value: String
  var children = [Node]()
  init() {   
  value = " "
  }
}

错误信息说:

main.swift:29:21: error: argument passed to call that takes no arguments
let m0= Node(value:"wash")

这是我的指示:

1. Edit a file named "main.swift"                                                  
2. Create a class called Node                                                   
3. Do not specify access modifiers
4. Create a property called "value" of type string                                
5. Create a property called "children" of type array of Nodes
6. Create a default constructor which initializes value to an empty string and children to an empty array
7. Create a constructor which accepts a parameter named value and assigns it to the appropriate property 

您忘记创建一个接受参数的构造函数(初始化函数)(第 7 步),这就是错误指出调用不带参数的原因。通过添加value参数,我们可以接受它,然后将其赋值给相应的变量。

class Node {
  var value: String
  var children = [Node]()

  init() {
      value = ""
      children = [Node]()
  }

  init(value: String) {   
    self.value = value
  }
}

let m0 = Node(value: "wash")