-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface A : NSObject | |
- (int)foo; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "A.h" | |
#import "B.h" | |
@implementation A | |
- (int)foo { | |
[B bar]; | |
return 1; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@interface B : NSObject | |
+ (void)bar; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "B.h" | |
#import "MyProject-Swift.h" | |
@implementation B | |
+ (void)bar { | |
[C fooBar]; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class C: NSObject { | |
public static func fooBar() -> Int { | |
println("Swift code is running") | |
return 3 | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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