Hi,
This problem has occurred quite often for me.
For example,
I declare a file MyStruct.swift
I put this into a folder (I personally use the MVC model, so in this case I'm moving this file to the Model folder).
Let's say that I have AnotherFile.swift with a view controller with a fairly trivial amount of code and this code block.
When the file MyStruct.swift is in the Model folder (i.e. AppName/Model/MyStruct.swift and AppName/AnotherFile.swift), it does the above code block gives an error saying that it doesn't recognize the 'MyStruct'. However as soon as I move the file out of the Model folder (i.e. AppName/MyStruct.swift and AppName/AnotherFile.swift), it compiles fine. I'm not sure why this happens. Any help would be appreciated!
I use Xcode 11.5
This problem has occurred quite often for me.
For example,
I declare a file MyStruct.swift
Code Block swift struct MyStruct { let memberOne : String let memberTwo : String }
I put this into a folder (I personally use the MVC model, so in this case I'm moving this file to the Model folder).
Let's say that I have AnotherFile.swift with a view controller with a fairly trivial amount of code and this code block.
Code Block swift ... var anArray : [MyStruct] = [ MyStruct(memberOne: "H", memberTwo: "W"), MyString(memberOne: "e", memberTwo: "o") ] ...
When the file MyStruct.swift is in the Model folder (i.e. AppName/Model/MyStruct.swift and AppName/AnotherFile.swift), it does the above code block gives an error saying that it doesn't recognize the 'MyStruct'. However as soon as I move the file out of the Model folder (i.e. AppName/MyStruct.swift and AppName/AnotherFile.swift), it compiles fine. I'm not sure why this happens. Any help would be appreciated!
I use Xcode 11.5
When you move the file, are you moving it with the Finder, or with the Xcode project navigator (the list of files on the left side of Xcode)?
If you’re using the Finder, you might notice that the file turns red in the Xcode project navigator after you move it. This is because Xcode projects have their own list of files in the project, and the Finder doesn’t know that it needs to update that list. You can either drag the file around in the Xcode project navigator to move it, or correct it afterwards by selecting the red file in the project navigator, then using the first tab of the inspector (the pane on the right side of Xcode) to set the new location.
If you’re using the Xcode project navigator to move the file, moving probably ought to just work. You might want to talk with someone in the Xcode Open Hours labs about what you’re seeing—it may be a bug. If the file doesn’t turn red after you move it, cleaning your project (Product > Clean Build Folder) might work around the problem.
If you’re using the Finder, you might notice that the file turns red in the Xcode project navigator after you move it. This is because Xcode projects have their own list of files in the project, and the Finder doesn’t know that it needs to update that list. You can either drag the file around in the Xcode project navigator to move it, or correct it afterwards by selecting the red file in the project navigator, then using the first tab of the inspector (the pane on the right side of Xcode) to set the new location.
If you’re using the Xcode project navigator to move the file, moving probably ought to just work. You might want to talk with someone in the Xcode Open Hours labs about what you’re seeing—it may be a bug. If the file doesn’t turn red after you move it, cleaning your project (Product > Clean Build Folder) might work around the problem.