一尘不染

Swift错误:源文件中的编辑器占位符

swift

您好,我正在实现图形数据结构。当我尝试构建应用程序时,出现错误“源文件中的编辑器占位符”

完整的图形实现是从WayneBishop的GitHub此处https://github.com/waynewbishop/SwiftStructures提取的

class Path {

var total: Int!
var destination: Node
var previous: Path!

init(){
    //Error happens on next line
    destination = Node(key: String?, neighbors: [Edge!], visited: Bool, lat: Double, long: Double)
     }
}

我将Node课程更改为:

public class Node{

var key: String?
var neighbors: [Edge!]
var visited: Bool = false
var lat: Double
var long: Double

init(key: String?, neighbors: [Edge!], visited: Bool, lat: Double, long: Double) {
    self.neighbors = [Edge!]()
     }

}

到目前为止,我在构建的所有代码中均发生了5次此错误。也有人问过这个问题,但没有回答。

我认为该错误可能是由于我init()Node课程的更改所致。在我更改之前,它只是init()。如果是,如何将对象添加到类中?如果我的编程术语不正确,请原谅我,因为我是OOP的新手。


阅读 213

收藏
2020-07-07

共1个答案

一尘不染

你有这个

destination = Node(key: String?, neighbors: [Edge!], visited: Bool, lat: Double, long: Double)

上面是占位符文本,您需要插入一些值

class Edge{

}

public class Node{

  var key: String?
  var neighbors: [Edge]
  var visited: Bool = false
  var lat: Double
  var long: Double

  init(key: String?, neighbors: [Edge], visited: Bool, lat: Double, long: Double) {
    self.neighbors = [Edge]()
    self.key = key
    self.visited = visited
    self.lat = lat
    self.long = long
  }

}

class Path {

  var total: Int!
  var destination: Node
  var previous: Path!

  init(){
    destination = Node(key: "", neighbors: [], visited: true, lat: 12.2, long: 22.2)
  }
}
2020-07-07