0

I'm building an app that relies heavily on an api response. The app needs to make this request every time it is launched. However this request takes 60~ seconds. Is there any way to save the response between tests so I can build/test the features that rely on the response?

In short, I don't want to call the server every time I test the app. I'm in swift

Marcus
  • 9,032
  • 11
  • 45
  • 84
  • If you don't want to call the server every time the app launches, what makes you think your potential customers are going to want to do that? The answer to your question may require a rewrite of the fundamental behavior of your application. – pbush25 Jul 06 '15 at 19:20
  • I'm only talking about testing. The app is async so it's not an issue for the user. – Marcus Jul 06 '15 at 19:22

1 Answers1

0

What I do is to write conditional code, dependent upon some environment variable, so that I'm not contacting the server but using some constant instead.

Thus, when I'm just testing and developing the rest of the my app, I just throw the environment variable switch, and presto, I'm using that constant.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • Turning an environment variable on or off is as simple as checking or unchecking a checkbox in the scheme (or you can switch schemes, of course). See my answer here: http://stackoverflow.com/questions/24003291/ifdef-replacement-in-swift-language/24344459#24344459 The actual example I give there involves the music library, not a server, but it is exactly parallel because the music library doesn't exist when I'm testing on the simulator, so I need some built-in data to use instead. – matt Jul 06 '15 at 19:25