Of course there are big open source projects supported by big companies, but there’s still no upfront cost to end developers so they do “come free”.You are conflating the cost to developers as a product and the development process for these tools. Many popular open source tools and frameworks are often supported through big institutions, foundations, or donations, e.g. Swift (Apple), React (FB), Node (OpenJS Foundation), npm (Github/MS) etc. Yes they are made available for free, but that doesn't mean there was no development cost.
And there are lots of (high-quality) OS projects designed & developed by independent devs. I’ve used and contributed to plenty of them.
But good point, the fact that most if not all of the largest tech companies contribute to open source means Apple can absolutely afford to develop & maintain the APIs for their own products especially if that means a healthier and more attractive ecosystem and products.