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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35167123/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:24:54  来源:igfitidea点击:

Swift Error: Editor placeholder in source file

iosswiftclass

提问by Lucas Crostarosa

Hello I am implementing a graph data structure. When I try to build the application the I get the error "Editor placeholder in source file"

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

The full graph implementation was pulled from WayneBishop's GitHub from here https://github.com/waynewbishop/SwiftStructures

完整的图实现是从这里https://github.com/waynewbishop/SwiftStructures从 WayneBishop 的 GitHub 中提取的

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)
     }
}

I changed the NodeClass around to:

我将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!]()
     }

}

This Error happens 5 times throughout the code that I have built so far. Also this question has been asked, but not answered.

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

I think the error may be due to my changes to the init()in the Nodeclass. Prior to my changes it was just init(). If it is, how can I add objects to the class? Pardon me if I am not correct in my programming terminology, as I am relatively new to OOP.

我认为错误可能是由于我init()Node课堂上的更改造成的。在我更改之前,它只是init(). 如果是,我如何将对象添加到类中?如果我的编程术语不正确,请原谅我,因为我对 OOP 比较陌生。

采纳答案by David Yang Liu

you had this

你有这个

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

which was place holder text above you need to insert some values

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

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)
  }
}

回答by Vishal Chaudhry

Sometimes, XCode does not forget the line which had an "Editor Placeholder" even if you have replaced it with a value. Cut the portion of the code where XCode is complaining and paste the code back to the same place to make the error message go away. This worked for me.

有时,即使您已将其替换为值,XCode 也不会忘记具有“编辑器占位符”的行。剪切 XCode 抱怨的代码部分并将代码粘贴回同一位置以使错误消息消失。这对我有用。

回答by Ahtazaz

After Command + Shift + B, the project works fine.

Command + Shift + B 后,项目运行正常。

回答by KingKongCoder

Clean Build folder + Build

清理构建文件夹 + 构建

will clear any error you may have even after fixing your code.

即使在修复代码后,也会清除您可能遇到的任何错误。

回答by XpressGeek

Go to Product> Clean Build Folder

转到产品>清理构建文件夹

回答by Vishnu gondlekar

Error is straight forward and its because of wrong placeholders you have used in function call. Inside inityou are not passing any parameters to your function. It should be this way

错误是直接的,这是因为您在函数调用中使用了错误的占位符。在内部,init您没有将任何参数传递给您的函数。应该是这样

destination = Node("some key", neighbors: [edge1 , edge2], visited: true, lat: 23.45, long: 45.67) // fill up with your dummy values

Or you can just initialise with default method

或者您可以使用默认方法进行初始化

destination = Node()

UPDATE

更新

Add empty initialiser in your Node class

在您的 Node 类中添加空的初始化程序

init() {

}

回答by Cihan Necmi Gunal

If you have this error while you create segues with the view controllers not with the UI elements you have to change sender: Any?to this

如果您在使用视图控制器而不是 UI 元素创建 segue 时遇到此错误,则必须更改sender: Any?为此

@IBAction func backButtonPressed(_ sender: Any) {
        performSegue(withIdentifier: "goToMainScreen", sender: self)

    }

It will work.

它会起作用。