Unfortunately, the choice of internal storage for your model iMac was the worst possible, in that the 500GB hard drive you have installed was a 5400rpm model. These iMacs also came with a 1TB Fusion (or Hybrid) drive option as well as a 256GB SSD option, both of which are significantly faster (especially the SSD).
So, to answer your question as asked, you can in fact replace the hard drive in your model iMac if you want, although Apple does not 'officially' consider the storage (i.e. HDD/SSD) in any of the Tapered Edge aluminum iMacs to be upgradable. However, to be fair to Apple, upgrading this is extremely difficult and I would not recommend anyone having a go at it unless they're experienced or are very technically competent.
Based on your specs, your iMac has the model identifier iMac14,4 (you can double-check this via the About This Mac option under the Apple Menu - click the System Report button). Instructions on upgrading your storage, along with videos, are available here.
Remember though, this is not easy!
Your particular model iMac only came with 8GB RAM and this was soldered onto the Logic Board, so cannnot be removed and replaced. There are no additional memory slots. In other words, this cannot be upgraded whatsoever.
In terms of external storage, the fastest option would be to use an SSD in an external enclosure connected to one of your Thunderbolt ports. Here are some example options. However, you'd have to factor in the cost of the SSD and enclosure and decide whether that money would be better put towards a different Mac? The fact is that your model iMac is not really suited to heavy work as it's throttled by a lack of both processing power and RAM.
Also, as a test, I used a mid-2010 iMac with a 500GB hard drive installed and launched Xcode and compiled a few builds to the simulator and in all instances these were a lot quicker than the 15 mins you talk about. Of course, without compiling the same code this is not a fair comparison. However, this iMac did have 12GB of RAM installed and that is a 50% boost compared to what you will ever have for yours.
- I would bite the bullet and start saving for another Mac.
- Upgrading the internal hard drive is very difficult and I assume beyond your competency (no offense intended)!
- In the meantime, I would ensure you keep your simulator running after first launch to significantly reduce subsequent builds etc.
- You could also run an Apple Diagnostics Test to check your hardware to ensure there isn't some other undiagnsed problem. To do this, restart your iMac and immediately hold down the D key. When prompted, run the tests. If you get the option to run an extended test, select this as well. Note this may take some time to run!
Any problems/questions, let me know.