Objective C test class using Swift code

前端 未结 2 526
轮回少年
轮回少年 2021-02-05 14:37

I have a swift protocol IModelIdProvider in the MyProjectName folder. I have created an objective-c unit test class named RemoteModelFactoryTest<

相关标签:
2条回答
  • 2021-02-05 15:30

    To import a set of Objective-C files in the same framework target as your Swift code, you’ll need to import those files into the Objective-C umbrella header for the framework.

    To import Swift code into Objective-C from the same framework

    Under Build Settings, in Packaging, make sure the Defines Module setting for that framework target is set to Yes. Import the Swift code from that framework target into any Objective-C .m file within that framework target using this syntax, and substituting the appropriate names...

    https://developer.apple.com/library/prerelease/ios/documentation/swift/conceptual/buildingcocoaapps/MixandMatch.html#//apple_ref/doc/uid/TP40014216-CH10-XID_75

    0 讨论(0)
  • 2021-02-05 15:41

    I know its extra hacky and everything, but what I did and it worked was to copy public headers from generated "Project-Swift.h" and paste whats needed to .m file of test.

    So I copied something like this:

    SWIFT_CLASS("_TtC10Inventorum11ImageEntity")
    @interface ImageEntity : NSObject <FICEntity>
    @property (nonatomic, copy) NSString * imageID;
    @property (nonatomic) NSURL * retinaImageURL;
    @property (nonatomic) NSURL * nonRetinaimageURL;
    @property (nonatomic, readonly) NSURL * imageURL;
    @property (nonatomic, readonly, copy) NSString * UUID;
    @property (nonatomic, readonly, copy) NSString * sourceImageUUID;
    @property (nonatomic) RACSignal * rac_signalForImage;
    - (instancetype)init OBJC_DESIGNATED_INITIALIZER;
    - (NSURL *)sourceImageURLWithFormatName:(NSString *)formatName;
    - (FICEntityImageDrawingBlock)drawingBlockForImage:(UIImage *)image withFormatName:(NSString *)formatName;
    - (void)objc_setType:(NSString *)type;
    @end
    

    And on top of this I have also copied all the macros for SWIFT_CLASS etc. My tests are building and passing testing Swift code.

    BTW. Dont forget to put public on tested classes and methods in Swift.

    0 讨论(0)
提交回复
热议问题