Yes your Apple PC (Mac or iPad) can get viruses or spyware.
In the past the Apple products just represented a very small amount of the total PCs in operation. This has a great effect on malware written for Apple products. The Apple operating systems are more secure than Windows and do block some malware better also, but there are ways to get around that protection. If you live in a complex with a guard at the entrance then theoretically the only people in your neighborhood are people who live there or approved by the security guard. I would suspect everyone still locks their house and cards.
As a result of Apple not used as much, people that write malware (viruses, spyware, ransom ware, etc), tended to not write malware toward that audience. They chose to write malware for Windows computers as that was where the most machines were that they could attack. Similar on the same approach as Willie Sutton, the famous bank robber on why he robbed banks, “because that is where the money is”.
Now as Apple products have gotten much more popular and some items such as the iPad are most popular in their category, the Windows machines are not just where money is anymore. I have had people contact me several times in last few weeks with either spyware or ransom ware on the iPads or Macs.
You need to run an anti-virus on your computer devices whether Windows PCs, Macs, iPads, smart phones. A number of the same companies that make anti-virus programs for PCs doe for Apple products too. Norton sells a version for Macs. Avast (which I currently use on my PC and Android phone) is available with versions fro Windows, Apple and android phones
If you do get infected with ransom ware and it says to call a number (some times claiming to be police, FBI or you internet provider (ISP)), do not call it as they now they have a legitimate number and may infect your phone also.