The Unix-based macOS operating system is fundamentally different from Windows in a number of ways, meaning that any attacker hoping to infect Macs would need to create custom code tailored specifically to the operating system.
The platform simply doesn’t have a large enough user base to make it worth the time for attackers to custom-build specific attack packages for the operation system’s unique features. Macs aren’t immune to viruses, but they also aren’t typically targeted by attackers. Reputable malware scanning software or antivirus software is a good addition to any secure system. And while Macs are rarely targeted by viruses, it pays to be careful. While the operating system does have some protections that can make viruses less powerful, that doesn’t mean macOS is airtight. This is true, but not because macOS is inherently better than Windows. Apple has frequently said that Macs don’t get infected by viruses.