I don't think any operating system can protect from attacks. There is a lot of code in an operating system and that code is written by human beings who makes mistakes. And some stuff that evil people do cannot be forseen by the good guys who develop the operating system. Do you think they forsaw buffer overflow attacks?
Even if the operating system is fairly bulletproof the applications may be soft targets. Some people trying to attack Mac OS X have targeted applications like Safari, Mail, Quicktime, iTunes, etc.
Some operating systems have few malware directed at them simply because the operating system is so uncommon it is a waste of time for the bad guys to develop the malware.
Other operating systems like Unix do not have a lot of malware directed at them because the bad guys did not necessarily want to target the servers. If you bring down the entire internet you might make a name for yourself in some circles and spend some time in prison. But the bad guys want to make money and if they bring down the internet they don't make a dime. They target the desktop computers that 90%+ of everybody uses-Microsoft Windows.
Now without a doubt an operating system can be written with security in mind from the beginning. But errors in coding will be made regardless. The coding is just too complex to be perfect. And some attacks cannot be forseen.
There is no such thing as an operating system that cannot be defeated. And even if the operating system was perfect, the weak link might be applications, at least third part applications.
If people study something long enough, they can defeat it. It does not matter if you are talking about castles, tanks, battleships, or operating systems. People are clever and people can be evil.