Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access swift files in Unit test target in Xcode

Adding swift files to test target will work, but it is not the best way to do. My problem is I can't able to access Swift file whereas Objective-C files are accessible.

I have checked product module name and set configuration file same as project file for test target. Even removed the test target and readded, but, still encountering "Use of undeclared type in SlideViewController".

Can anyone help me with solving this issue?

like image 344
guru Avatar asked Jun 20 '17 06:06

guru


1 Answers

By default you won't be able to access internal classes from your unit test target.

The apple docs on writing tests with swift say that you need to take two steps to get around this:

  1. Set the ENABLE_TESTABILITY build setting to YES.
  2. Add @testable to the import statement for your module. @testable import MySwiftApp

If you follow both of those steps your SlideViewController (as long as it is not a private class) should be accessible from your unit test file as if it was declared as an open class.

like image 122
N Brown Avatar answered Sep 21 '22 12:09

N Brown