Swift Error: Editor placeholder in source file

IosSwiftClass

Ios Problem Overview


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

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 Node Class around to:

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.

I think the error may be due to my changes to the init() in the Node class. 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.

Ios Solutions


Solution 1 - Ios

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.

Solution 2 - Ios

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

Solution 3 - Ios

Go to Product > Clean Build Folder

Solution 4 - Ios

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

Solution 5 - Ios

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

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

init() {
   
}

Solution 6 - Ios

Clean Build folder + Build

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

Solution 7 - Ios

In my case, using Item instead of item was causing the problem, here's come with a comment

struct AspectVGrid<Item, ItemView>: View where ItemView: View, Item: Identifiable {
    var items: [Item]
    var aspectRatio: CGFloat
    var content: (Item) -> ItemView


    var body: some View {
        let width: CGFloat = 100
        LazyVGrid(columns: [GridItem(.adaptive(minimum: width))]) {
            ForEach(items) { item in
                // using Item instead of item caused the problem
                content(Item).aspectRatio(
                        aspectRatio,
                        contentMode: .fit)
            }
        }
    }
}

Solution 8 - Ios

I had the same issue. This works for me:

  1. Product -> Build Clean Folder

  2. Product -> Build

Solution 9 - Ios

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

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

It will work.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionLucas CrostarosaView Question on Stackoverflow
Solution 1 - IosVishal ChaudhryView Answer on Stackoverflow
Solution 2 - IosAhtazazView Answer on Stackoverflow
Solution 3 - IosXpressGeekView Answer on Stackoverflow
Solution 4 - IosDavid Yang LiuView Answer on Stackoverflow
Solution 5 - IosVishnu gondlekarView Answer on Stackoverflow
Solution 6 - IosKingKongCoderView Answer on Stackoverflow
Solution 7 - IosmirkancalView Answer on Stackoverflow
Solution 8 - IosTaimoor ArifView Answer on Stackoverflow
Solution 9 - IosCihan Necmi GunalView Answer on Stackoverflow