Xcode has started to show numerous errors within my project.
Everytime I build my app the number of errors changes. It's always between 50 and 70 errors that cause the build to fail.
The errors are always 1 of these 2.
Cannot convert return expression of type '()' to return type 'UICollectionReusableView'
or
Cannot convert return expression of type '()' to return type 'UICollectionViewCell?'
Whenever I click an error it opens up that file, shows no error in code and then the error in the issue navigation for that file disappears.
In addition, the errors are always related to collection views, yet Xcode is showing errors for simple extension files or enum files, which have nothing to do with collections.
I have cleaned the project build folder, removed the derived data, restarted Xcode, restarted the laptop, even reinstalled Xcode yet I still get the errors
I've gone back through my previous 5 days of commits and I've found the offending code.
dataSource.supplementaryViewProvider = { [weak self] (view, kind, index) in
guard let self = self else { return }
return self.collectionView.dequeueConfiguredReusableSupplementary(
using: headerRegistration, for: index)
}
I was updating my code with better memory management. However, when typing on autopilot I overlooked the need to return a cell from the guard statement. Xcode didn't present a warning untill flagging issues in the 20+ files when trying to build.
The following code builds successfully.
dataSource.supplementaryViewProvider = { [weak self] (view, kind, index) in
return self?.collectionView.dequeueConfiguredReusableSupplementary(
using: headerRegistration, for: index)
}