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.
Hi everyone. I’m new to using Xcode and this is my first time coding. I’m currently following some tutorials that require this coding to create a rectangle:
let canvas = UIView(frame: CGRectMake(0, 0, 200, 200)). I know that CGRectMake was removed from xcode so I changed my code to
let canvas = UIView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
I’m getting a swift compiler warning of ‘editor placeholder in source file’. Can someone tell me how to fix this and why i’m getting it?
Accepted Reply
When you insert code via autocompletion (or via a code snippet, sometimes), there may be placeholders — blue rectangles that describe what you should put there instead. You can click on a placeholder to select it, then type your actual code.
For example (I’m guessing) when you typed «UIView(«, you inserted a complete call, but with a «CGRect» placeholder where the rect was supposed to go. If you put the rect parameters after the placeholder without replacing it, you’d get this error message. You should have replaced the placeholder, not used it as code.
If that’s what happened, you don’t have to actually retype it in this case. If you double-click on a placeholder (or select it and press Enter), it will change to regular text.
Replies
When you insert code via autocompletion (or via a code snippet, sometimes), there may be placeholders — blue rectangles that describe what you should put there instead. You can click on a placeholder to select it, then type your actual code.
For example (I’m guessing) when you typed «UIView(«, you inserted a complete call, but with a «CGRect» placeholder where the rect was supposed to go. If you put the rect parameters after the placeholder without replacing it, you’d get this error message. You should have replaced the placeholder, not used it as code.
If that’s what happened, you don’t have to actually retype it in this case. If you double-click on a placeholder (or select it and press Enter), it will change to regular text.
That’s exactly what I did by the looks of it. I’ve double-clicked and its changed and given me the rectangle I needed. Thanks!
Command + Shift + b
It works perfectly… I have already done this for tableView
In addition to the solution offered by Quincey Morris, if you can’t find said placeholder, try closing and reopening your project, or even Xcode.
Thank you @Anam098 it worked.
I am trying to create a button on apple maps that will relocate the user if he or she navigates elsewhere.
I found some old solutions to this problem for like ios 7 or 8 which no longer worked in ios 9. This is what I tried
@IBAction func locateMe(sender: AnyObject) {
self.mapView.setUserTrackingMode(MKUserTrackingMode, animated: true)
}
there are no errors before I try to run it but when I do it says: editor placeholder in source file
asked Oct 12, 2015 at 18:57
![]()
RubberDucky4444RubberDucky4444
2,3105 gold badges36 silver badges70 bronze badges
1
I didn’t solve the bug issue, But i did realize how easy it was to get the re auto locate button to work. The code that I used to initially get the auto location just needs to be copied and pasted into the button action brackets and will rerun the code when tapped.
answered Oct 13, 2015 at 5:12
![]()
RubberDucky4444RubberDucky4444
2,3105 gold badges36 silver badges70 bronze badges
1
import UIKit
import AVFoundation
class ViewController: UIViewController {
@IBAction func buttonPressed(_ sender: Any) {
let device = AVCaptureDevice.default(for: AVMediaType.video)
if device!.hasTorch {
do {
try device?.lockForConfiguration()
device?.torchMode = device!.torchMode == AVCaptureDevice.TorchMode.on ? .off : .on
device?.unlockForConfiguration()
} catch {
print(error)
}
}
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
}

Что за ошибка и как исправить?
Ответы (1 шт):
Xcode любит «тупить» и выдавать не актуальные ошибки. По конкретно этой — он пытался собирать когда был placeholder кода. Возьмите на вооружение сочетание клавиш:
Cmd+Opt+Shift+K - очистить и после этого перебилдить Cmd-B
Многие проблемы после этого уходят и больше не сбивают с толку.
→ Ссылка
Solution 1
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 2
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 3
After Command + Shift + B, the project works fine.
Solution 4
Go to Product > Clean Build Folder
Solution 5
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() {
}
Comments
-
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
NodeClass 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 theNodeclass. Prior to my changes it was justinit(). 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. -
so dummy values need to be placed in the initializer in order for them to compile?
-
Its not dummy value, you need to initialise with data available with you at that time. If not you can pass empty data. Else use second way around to initialise
-
I tried that and it returns an error «Cannot Invoke Initializer for Type ‘Node’ with no arguments`
-
returns error Initializer does not override a designated initializer from its superclass……Could this have anything to do with Inheritance? Maybe move the destination to another file/class?
-
okay I added an empty initializer, but it errors out with «Return from initializer without initializing all stored properties» unless I fill in dummy values for the variables. Do I need to keep it that way? If so, how do I add a new object?
-
You can set which ever data is available at that point of time. To remove that error, declare your vars optional i.e
var neighbors: [String!]!var lat: Double!var long: Double! -
So with this, how can I add a new object? Right now I cannot say var hello = Node(key: «hey»…). is it through overrides?
-
I found cut/paste didnt work sufficiently, but rebuilding did the trick. Product -> Build Clean Folder, Product -> Build
-
Cut and pasting the line on same line silenced «Editor placeholder in source file». The error started after I paste a middle sized block of code.
