I have a late 2013 MacBook Pro 13" with 8 GB of memory. Lately my MacBook Pro uses swap memory, when it has enough free memory. Is this normal and can I do something about it? Also when I only have safari and let's say Xcode open it uses 99% of the RAM. Is this normal behavior?
This is normal behavior. You are not experiencing any memory issues in your screenshot above. What I suspect is happening is that OS X is creating some placeholder of sorts to enable swap memory, rather than actually using swap memory here. I have never seen a zero in the swap memory section, unless I have just restarted and open the Activity Monitor window fresh, and even then, I rarely see zero.
With Mavericks and Yosemite, the way the OS uses memory changed a bit. Essentially, the OS takes all the memory, and then manages it out as needed. So, our traditional way of looking at the memory report in Activity Monitor is not really valid. Due to this, Mavericks added the 'Memory Pressure' gauge, to give you an idea of when you have a limitation caused by memory. In your screenshot, you have a green memory pressure. For more see this answer.
Ars Technica has a nice description of this 'memory compression' in their Mavericks review:
You would need to be monitoring the memory and swap usage as the swap file was created to have a chance to understand why the swap was created. Based on what you describe in text and in the screen shot, I see nothing that is concerning.
As to why swap was created when you assume you had free RAM. The OS can move to swap based on predictive measures. For example, maybe you started up Photoshop which had several large image files automatically reopen from a prior session. The OS could see that there was suddenly a huge new demand on RAM, and moved some unused RAM content to swap in advanced of an expected need.
Or your backup program briefly ran in the background, and did a huge number of file checksums and comparisons and created large RAM based data structures, pushing other content to swap. Then the backup program released its RAM and went back to sleep.
Mac OS X (and most modern OS: Windows, Linux, etc) are very intelligent about automatically using Cache, Swap, memory compression and other techniques to keep the system running as fast as possible. I really would not be worrying about this unless you see that the Activity Monitor is reporting that Memory Pressure is in the Yellow or Red zone.
I currently have a 2010 13" MacBook Pro that has 16GB of RAM. I do lots of work that is heavy on RAM usages. (Web Development, data mining, running many heavy duty apps at the same time.) Even with 16GB I sometimes hit the Yellow zone for memory pressure. But I have to say this is seldom an issue because Mac OS X is very good about allocating resources as needed.
While I need the 16GB of RAM for my work, you should know that such an upgrade is not without negatives. The extra RAM does significantly reduce battery life both in active usage and in sleep.
Your Mac runs on Unix ( certified Single Unix Specification 2003 ), and that OS has been around for 40+ years. Core components (like memory management) are written, updated, debugged and polished by people who are definitive experts in the field. Apple, with more cash on hand than the US Treasury, can afford to hire the absolute best.
So, unless you have at least a PhD in theoretical computer science, and wrote your thesis on kernel-level process and memory management, stop worrying about the memory management. I have 24Gb in my desktop and it still uses swap. This concerns me not at all.