Let said I have Swift and Objc classes, and a MyProject-Bridging.h
BazSwiftClass.swift
public class BazSwiftClass: NSObject {
public let foo: String
@objc init(foo: String) {
self.foo = foo
}
}
FooClass.h
#import "MyProject-Swift.h"
@interface FooClass : NSObject {
- (BazSwiftClass)bazMethod;
}
I want to access the FooClass.h
in another Swift Class (let said BarSwiftClass)
public class BarSwiftClass {
public hello() -> BazSwiftClass {
return FooClass().bazMethod()
}
}
I need FooClass.h in my swift file, so I added FooClass in my MyProject-Bridging.h
#import "FooClass.h"
So the Flow is like BarSwiftClass -> FooClass -> BazSwiftClass
It can't work because the compiler show "failed to emit precompiled header" and I think it is because of #import "FooClass.h"
in MyProejct-Bridging.h
Please help.
Thank you.
Replace your code
#import "MyProject-Swift.h"
@interface FooClass : NSObject {
- (BazSwiftClass)bazMethod;
}
With
@class BazSwiftClass
@interface FooClass : NSObject {
- (BazSwiftClass)bazMethod;
}
and in FooClass.m File you can import #import "MyProject-Swift.h"