Both iOS / iPadOS do not allow any rogue code to run. Only Apps from the App Store. Yes, there are vulnerabilities but providing you keep the mobile devices up to date the risks are extremely low. I've only heard of nationstate hacking going on with Apple mobile devices. So dissidents, authors, news media, etc. being specifically targeted by government hackers.
With Macs you have more freedom and with it comes greater risk of malware. You need to really be on your toes with both phishing via email and text messages or any other messaging apps. You should only install software from the Mac App Store and if you do need software that is not on the App Store that you download it directly from the manufacturer / developers website that you manually navigated to yourself. That software should be signed and notarized and if it's not, you should seriously question its legitimacy. When you run software that has not been signed nor notarized you will see a warning from Apple. Do not become accustomed to just allowing it to run. Most developers have done the right thing and both signed an App and submitted it to Apple so they can notarize it. Notarization means that Apple has verified it is not including malware.
Be wary of free games not distributed via the App Store as many include adware as a source of income. Avoid those download sites with shareware as they also bundle adware as a revenue stream. Most things that are free are finding some way to generate revenue. Even on the Apple App Store there have been Apps with ridiculous subscription models or in App purchases that have taken advantage of people. Apple has been cleaning that mess up lately.
The big one is to never pirate software. It's just too juicy a target for malware. Sure you might be getting some commercial software for free but it's highly likely to include a malicious payload coming along for the ride.
Running an ad blocker is highly recommended. I've come across many rogue ads even on mainstream websites that auto downloaded a bit of malware. Advertising networks accept small outfit ads and feed them through the network. Many are not doing the due diligence of testing the advertisements. Now and then some rogue advertisement delivers a download that might run automatically. Other ads are fake security warnings about your computer being hacked, etc. Do not click on these as they will either deliver malware or try to fool you into installing fake security software as you've discovered with MacKeeper.
Beware of scammers calling your phone claiming to be Apple or Microsoft and telling you that you are infected. Do not establish a remote control session with these scammers. Do not engage with them at all. Just hang up.
Why is malware / adware such a massive problem? Well it costs the scammers next to nothing and the returns are massive. Millions of people around the world are fooled continuously. Billions of dollars are stolen worldwide every year. Hundreds of millions in the USA alone.
It is recommended to be far more skeptical about software and to think twice before installing any software. It's now a zero trust world. The scammers are out there and there is massive financial incentive for them to scam as many people as possible in every conceivable way.