33

is it possible to edit the hosts file of the iPhone simulator?

I'm working on a REST API and I need to be able to access my local site using a correct domain (e.g. http://api.local.com)

Shiki
  • 16,688
  • 7
  • 32
  • 33

1 Answers1

52

You can simply edit your Mac's /etc/hosts file and iPhone Simulator will adopt whatever is set there.

It works because the iPhone Simulator simply provides a simulated frontend of Mobile Safari's user interface, which just uses your Mac's network settings.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • 1
    There is some [indication](http://stackoverflow.com/questions/25973476/xcode-6-simulator-ignores-hosts-file-changes) that this behaviour has changed with the Xcode 6 iOS Simulator. Do you know anything about it BoltClock? – trojanfoe Sep 23 '14 at 07:59
  • @trojanfoe: Hmm, I don't think so :( I haven't had a chance to update to Xcode 6 yet. – BoltClock Sep 23 '14 at 08:12
  • It's not clear how the simulator would even work if it didn't rely on the OSX name resolution subsystem, so it could very well be a red herring. Anyway, cheers. – trojanfoe Sep 23 '14 at 08:13
  • 14
    I'm currently working on a project with Xcode 6 and editing /etc/hosts of host OSX doesn't seem to affect iOS Simulator. Here is a link to same issue with Xcode 6: http://stackoverflow.com/questions/25973476/xcode-6-simulator-ignores-hosts-file-changes – DUzun Oct 09 '14 at 14:43
  • 1
    I would love if Android simulator works the same way (it is not) – Mike Keskinov Feb 08 '20 at 01:50