Prior to OS X, there were viruses written for Apple Macintosh computers. Any operating system on which software can be installed at all is potentially vulnerable to infection from a virus, which is itself a form of software. An operating system cannot distinguish good software from bad software; this is usually done by antivirus scanners or behavior monitoring programs. In the past, bona fide "viruses" were mostly targeted at specific groups or individuals, such as politicians and high-profile clergymen, most of whom are non-technical users who will use whatever their employers provide (most likely Windows). But in the recent decades average users have been intentionally attacked for the purpose of notoriety or to cause grief. Viruses in themselves are intentionally destructive, rather than stealing information or providing control over someone's machine. While virus creation and infection has been on the downturn in favor of malware, infection is still entirely possible and not to be ruled out.
These days most malicious programs in the wild are Trojan horses. Software which supposes to be something it really is not, Like "MacDefender", or "AntiVirus 2011". Besides Trojans, there are also a lot of spyware and exploits that can infect a computer remotely and surreptitiously, usually through a Web browser. Unlike viruses, which are written out of malice, these parasites are written for profit, be it to direct a botnet to attack other networks, or to steal user information to sell to identity thieves.
Apple's Web site says that "a Mac is 100 percent safe from viruses designed to attack PCs." This is true; otherwise, Apple could face a class-action lawsuit. The loophole is a single, clever subtlety in the phrase, "designed to attack PCs."
There are in fact some Trojans written for Mac OS X, but no viruses. While Apple announces that their systems are "more resistant to attack" There are professional security researchers who have successfully compromised both Macs and Windows computers remotely, as well as other operating systems for PCs, servers, and even mobile devices like the iPhone.
It is widely believed that Unix-based operating systems cannot be infected at root level unless the user authorizes it with a password; this is untrue. All platforms have known privilege escalation vulnerabilities, and more are being discovered all the time.
At the time of writing, Windows users remain by far the most likely to encounter viruses, or any other type of malware/unwanted programs. In over 20 years, the total count of Mac viruses is about 50 (all prior to Mac OS X). There are thousands for Windows.
However, The unfortunate truth is ALL computers are susceptible to viruses or attack.
While the fallacy that "Mac's can't get viruses" is pushed by Apple, the truth of the matter is they are just as susceptible as windows users except they aren't being directly targeted being that Macintosh used to run less than 6% of the global operating system market share (Source: C|Net). As more users are moving over to the Macintosh OS, they recently have been receiving more malware traffic. Macs require signed software, making it difficult to get malware to run. But naive users make it's built in protections nearly useless like in the MacDefender malware exploit from 2011. The software required the user to accept the installation, under the guise of protection, but it turned out to be malware, launching pornographic websites while warning you that you have Malware installed and offering you to purchase the Full version of MacDefender to remove the fake virus for a large sum of money. (Source: C|net)
Recently a new threat has surfaced caused by a Java exploit, in which Apple took 6 weeks after Oracle (the current owner of Java) to patch (Source: Forbes), allowing more than 2 percent (Source: ComputerWorld) of scanned Macintosh systems to become compromised. Kapersky noted through an experiment that over 600,000 systems were connected to their experimental C&C (Command and Control) botnet server, over 98% are heuristically detected to have been Macintosh systems. (Source: SecureList)
So to say that Apple Computers do not get Viruses is a commonly perpetuated fallacy, pushed by Apple, and naive Mac users alike. The truth is that no computer system or operating system is truly secure, or free of viruses and malware.
All computers are at the same risks for viruses and spyware. (And Mac's can carry Windows viruses and can possibly infect Windows machines via Network, Hard Drive, or USB Jump Drive) So users need to be careful about what websites they visit and what they download off the internet because malware is everywhere and can really cause problems no matter what OS or computer manufacturer.