Can't get Xcode to parse the code in one file in editor

I'm a beginner so please forgive my use of wrong terminology.

I have been working through the Apple tutorial on SwiftUI. I tried to edit the PreviewProvider in "ContentView.swift" made a mistake and tried to revert back. I have checked that the code is now as it was when it worked.

But, the code in that file is not showing the same as before – it has none of the colours which show that Xcode has parsed and checked the code. Thus, the canvas is not showing. The code looks like this:

Nonetheless, the project builds and runs without error.

How can I make Xcode parse a file and thus show the canvas ?

Post not yet marked as solved Up vote post of Crudgle Down vote post of Crudgle
239 views

Replies

Xcode (starting from version 11, maybe) is buuuuuuuuuuuggy. It has big features, but fails miserably on small or tiny functionalities.

You can try right-click the file and select "View As->Source Code". If this does not work either, then remove the file and re-add it back (at least this worked for me once or twice).

imneo, thanks.

I can't find a "View As => Source Code" function. But there is a "Open As => Source Code". I tried that but nothing changed.

I took a clean copy of the "ContentView.swift" file from the downloaded Zip archive and replaced the existing copy. That also did not change anything. this suggests to me that the bug is in how Xcode uses the xcodeproj file.

Looking at my capture above, how is Xcode viewing the code ? As plain text ? As rich text ?

I've ditched the entire project and started again – that worked but really it's the nuclear option. I'm glad it's not a production project and is just the Apple tutorial.

UPDATE: I opened the old ContentView.swift file in TextEdit and copied and pasted my code into the new copy of ContentView.swift. Xcode seems happy.

Cheers.

  • You don't need to start over again. What I meant was remove the file by reference from the project and add it back again. This should work.

  • "remove the file by reference from the project and add it back again" <== I don't understand what "remove the file by reference" means. Is it a facility in Xcode ? Is there a setting somewhere in Xcode which lists files that are "attached" to or used by a project ?

    Anyway, I've moved onto to more tutorials.

    Many thanks.

Add a Comment