My SwftUI code suddenly started getting this error but only happens when using Canvas. Works fine in the Simulator and no errors or warnings. Any idea if this is a bug in SwiftUI or something in my code? I have looked at all of my # statements and they all seem to have matching # statments. I have also looked at the sorce code files in hex and they all seem to be ended properly with a 0A. sooo... don't know how else to continue.
swiftui extra tokens at the end of #sourceLocation directive
Could you post the part of code with the directive ?
You could try to
- copy the complete line as well as the next ones and check in a text editor for hidden characters
- remove completely the statement and type it again.
Hello, I know one cause of this error and I am assuming it is a bug in xcode. If you have comments on the same line as an opening bracket of a closure or an if statement or anything of that nature it will throw this error. As far as I know comments should have no effect on your code which is why I am pretty sure this is a bug but if you still have this issue check the lines with opening brackets for comments and delete them that should fix it!
Hope this helps
Current XCode Version: 11.4.1
As @espidle mentioned, removing any comments from the lines where there are open bracket seems to solve this for me.
I had this same problem June 28 2021 with xCode 12.5. I like to add a short descriptive comment at the start of a func() { But apparently it causes errors if the comment is not on a new line. The resulting error messages are very confusing. It cost me a few hours of misguided "fixes" and restoring from backups, before finding this forum post and explanation. Thanks for posting!
Apple is overdue to fix this.