Upd: The problem came back, and I managed to find the fix: it is to do with "live issues" in xcode settings->General!! Uncheck it and everything works fine.
https://stackoverflow.com/questions/73808435/xcode-errors-disappear
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: