All you can do is reduce attack surface, and most of all, monitor.
Another comment blames Apple, and financial incentives. Sure, there may be some of that.
But the reality is that safe code is impossible. Now, you may say "But...", yet think about this.
For all of computing history, all of it, no matter what language, no matter how careful, there is always a vulnerability to be had.
Thinking about software, and security any other way, is an immediate fail.
Arguing the contrary, is arguing that the endless litany of endless security updates, for the stuff discovered, doesn't exist.
And those updates oyly cover stuff discovered. There are endless zero days right now, being exploited in the wild, without patches, of which we are unaware.
We're seen vulnerabilities on every kernel, in mainline software, on every platform, sitting for years too. And you know those are discovered by black hats, and used for a long time before being found out by the rest of the community.
Humans cannot write safe software. Ever. No matter what.
Get over it.
Only detailed, targeted monitoring can help you detect intrusion attempts, expose as little as possible, keep updated, and do your best.