How to prevent iCloud from downloading (storing) certain files in an Xcode project in iCloud?
Such an option to force iCloud to keep some files would be nice. In the meantime, you can check OneDrive. It fits this purpose. You can decide if some files/ folders have to be kept offline.

A way is to use aliases. Then again, you'd have to check if Xcode can work with that. 


Whichever files/ folders are required offline, move them to a non-iCloud-synced place.
Make their aliases and keep them in place of the original files/folders.
If you need to sync those files somewhere else too, make another copy in iCloud. 


If aliases don't work, check out symlinks.