I may be in compiler hell right here.
I'm implementing a Snapshot test in Swift, calling a property on an Objective-C VC, but that property is a class, written in Swift, bridged in.
In MyViewController.h:
@class TextEntryView;
@interface MyViewController: AbstractTextEntryViewController
@property (nonatomic, strong) TextEntryView *textEntryView;
@end
In TextEntryView.swift:
@objc(TextEntryView) class TextEntryView: UIView
And in my test, I'm trying to call
vc.textEntryView
where vc is of type MyViewController
and I'm getting the error:
value of type
MyViewController
has no membertextEntryView
My bridging headers look good. If I add an NSString
property to the .h file above, I'm able to reference it in the test. Also, when I command-click on MyViewController
in my test, it takes me to the .h
file rather than the .swift
generated version of that file (which seems like a symptom of this problem).
I may be pushing Xcode 8 beyond its limits.
You need to make sure you import
your app at the top of the source file for your test. For example, if your app is called MyApp, insert at the top of the test file:
import MyApp
If I leave out the import
, I get the same behavior you are seeing. Additionally, as long as the import
is there, you shouldn't have to bother with bridging headers for the unit test.
Have you tried to import to Test Target ?
Since you already imported the Xcode-generated header file for your Swift code into Objective-C .m file.
Please also remove @objc
annotation from TextEntryView class since it's a subclass of UIView thus accessible and usable in Objective-C. keeping the annotation @objc may cause a side effect.
To be accessible and usable in Objective-C, a Swift class must be a descendant of an Objective-C class or it must be marked @objc.
a simple case of "side-effect" is when a (swift) UIViewController
subclass is marked @objc
and used as custom subclass in storyBoard:
instantiateViewControllerWithIdentifier
will instantiate a UViewController
instead of the subclass we set in the storyBoard.
with error Unknown class _TtC10AbcdViewController in Interface Builder file
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With