This is a quick note about the fact that if you get surprising or unexpected build errors in a swift project, cleaning the build products directory may clarify them. In AppCode, the fastest way by default is to press Cmd+Shift+A to open the action fuzzy search and type “Clean build folder”; in Xcode, the shortcut is Cmd+Opt+Shift+K.
There are two kinds of errors I’ve seen that are improved in this way:
Circular dependency
12
myapp/Model/MyModel.swift:11:8: error: circular dependency between modules 'Model' and 'ViewModel'
import ViewModel
In this example, the ViewModel target uses Model, but then ViewModel was imported in Model. The compiler found the previously built ViewModel in the products directory and tried to incrementally compile Model, producing a circular dependency between the two. If you clean the build products, you’ll see that ViewModel isn’t actually built yet by the time Model is built; you have a clearer error:
12
myapp/Model/MyModel.swift:11:8: error: no such module 'ViewModel'
import ViewModel
Library not loaded
1234
~/Library/Caches/JetBrains/AppCode2020.1/DerivedData/myapp-foobar/Build/Products/Debug-iphonesimulator/myapp.app
dyld: Library not loaded: @rpath/ReactiveSwift.framework/ReactiveSwift
Referenced from: ~/Library/Caches/JetBrains/AppCode2020.1/DerivedData/myapp-foobar/Build/Products/Debug-iphonesimulator/ViewModel.framework/ViewModel
Reason: image not found
This might happen when you’re launching a built application. In my case, ReactiveSwift is installed with CocoaPods, but apparently it’s not linked to a target in the application. Cleaning the build directory gives another error, which is not much clearer, but at least it happens while building, not at runtime:
12
ld: file not found: ~/Library/Caches/JetBrains/AppCode2020.1/DerivedData/myapp-foobar/Build/Products/Debug-iphonesimulator/myapp.app/myapp
clang: error: linker command failed with exit code 1 (use -v to see invocation)