Either always copy them to a separate hard drive or a flash drive when you're done. If you don't need to guarantee security, then use a service like dropbox to keep backups - They save every revision of your files, and it's free. There are other paid services if you need more storage.
If you have a second computer, you can also set up your own code repository and use that directly from Xcode.
Time Machine is also a good option, as while it's designed to back up all files, your code files should be included.
Backup is a huge topic, raging from simply keeping a second copy on a separate drive to multiple offsite backups of a RAID-1 array - it's all about how much the data is really worth to you if it were to be lost.