So I am creating an ObjC framework which has mix of ObjC and Swift code: UtilitiesFramework.
Here is my StringUtilities class in Swift:
@objc
public class StringUtilities: NSObject { }
I am accessing StringUtilities class in Utilities which is an ObjC class.
Here is Utilities.h which is returning StringUtilities and has a forward class declaration for same:
@class StringUtilities; // Forward Declaration
@interface Utilities: NSObject
- (StringUtilities *)stringUtilities;
@end
Here is Utilities.m which imports generated swift header file:
#import <UtilitiesFramework/UtilitiesFramework-Swift.h> // This should provide concrete implementation of StringUtilities
@implementation Utilities
- (StringUtilities *)stringUtilities {
return [StringUtilities new];
}
@end
I am exposing Utilites.h file to Swift through module.modulemap:
module PrivateObjC {
header "Utilities.h"
}
I have set the import path accurately in build settings as:
$(SRCROOT)/$(PRODUCT_NAME)
Now when I try to access Utilities class in some other swift class it just compiles fine:
import PrivateObjC
class SomeOperations {
func doSomething() {
_ = Utilities() // This compiles fine
}
However when I try to access the StringUtilities through its method, it gives compilation error:
import PrivateObjC
class SomeOperations {
func doSomething() {
_ = Utilities().stringUtilities() // This gives compilation error
}
Here are the errors:
value of type Utilities has no member stringUtilities: _ = Utilities().stringUtilities()
note: method stringUtilities not imported
- (StringUtilities *)stringUtilities
^
note: return type not imported
- (StringUtilities *)stringUtilities
^
note: interface StringUtilities is incomplete
- (StringUtilities *)stringUtilities
^
note: interface StringUtilites forward declared here
@class StringUtilities
I thought this scenario is fixed as part of proposal:
# 0384-importing-forward-declared-objc-interfaces-and-protocols.md
However it is not working for me. May be it is due to it being approved as part of Swift 5.9, whereas in my machine 5.8.1 is used or am I missing anything else over here?
Update: I installed Xcode 15 and double checked the swift version which is 5.9, however I am still getting the error. Any idea why it is not working for a framework target?