Skip to content

Instantly share code, notes, and snippets.

@YoniTsafir
Created May 29, 2015 09:59
Show Gist options
  • Save YoniTsafir/c1710ad63f948ae805ca to your computer and use it in GitHub Desktop.
Save YoniTsafir/c1710ad63f948ae805ca to your computer and use it in GitHub Desktop.
Importing Swift code from Objective-C in a Test Target - It's Possible!
@interface A : NSObject
- (int)foo;
@end
#import "A.h"
#import "B.h"
@implementation A
- (int)foo {
[B bar];
return 1;
}
@end
#import <XCTest/XCTest.h>
#import "A.h"
@interface ATest : XCTestCase
@end
@implementation ATest
- (void)testFooReturns1 {
A *a = [[A alloc] init];
XCTAssertEqual([a foo], 1);
}
@end
@interface B : NSObject
+ (void)bar;
@end
#import "B.h"
#import "MyProject-Swift.h"
@implementation B
+ (void)bar {
[C fooBar];
}
@end
public class C: NSObject {
public static func fooBar() -> Int {
println("Swift code is running")
return 3
}
}
import XCTest
class CTest: XCTestCase {
func testFooBarReturns2() {
XCTAssertEqual(C.fooBar(), 3)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment