The Mac is generally considered to be safe and secure, and there are a number of reasons why Macs are considered more secure than PCs. Malware writers are less likely to target Mac users because of the perception that it has a far smaller market share than Windows. There is also the fact that the Mac operating system is Unix-based, and Unix offers a number of security features built in.
In addition, Apple has included a number of security measures that make attacking a Mac particularly challenging. These include Gatekeeper, which blocks any software than hasn't been digitally signed and approved by Apple from running on your Mac without your agreement.
However, there are still risks and from time to time Macs have become targets. In fact a report has recently claimed that 2017 has seen a 230% rise in Mac malware. The report, by Malwarebytes, said too that the App Store for Mac is being overcome by scam software, a previously relatively small issue.
Examples of Mac malware
Despite Apple's best efforts, Mac malware does exist, e.g.
OSX/Dok
Security analysis firm CheckPoint Software Technologies spotted a new OS X malware at the end of April 2017.
Apple rushed to block it.
The macOS Trojan horse appeared to be able to bypass Apple’s protections and could hijack all traffic entering and leaving a Mac without a user’s knowledge - even traffic on SSL-TLS encrypted connections.
OSX/Dok was even signed with a valid developer certificate (authenticated by Apple) according to CheckPoint’s blog post. It is likely that the hackers accessed a legitimate developers’ account and used that certificate. Because the malware had a certificate, macOS’s Gatekeeper would have recognized the app as legitimate, and therefore not prevented its execution. Apple has since revoked that developer certificate and updated XProtect, it’s malware signature system.
The attacker could gain access to all victim communication by redirecting traffic through a malicious proxy server.
See article for more examples