How to let the app know if it's running Unit tests in a pure Swift project?

后端 未结 15 682
借酒劲吻你
借酒劲吻你 2021-01-30 05:08

One annoying thing when running tests in Xcode 6.1 is that the entire app has to run and launch its storyboard and root view controller. In my app this runs some server calls th

15条回答
  •  不思量自难忘°
    2021-01-30 05:29

    Other, in my opinion simpler way:

    You edit your scheme to pass a boolean value as launch argument to your app. Like this:

    All launch arguments are automatically added to your NSUserDefaults.

    You can now get the BOOL like:

    BOOL test = [[NSUserDefaults standardUserDefaults] boolForKey:@"isTest"];
    

提交回复
热议问题