'Unable to access SPM classes in Swift classes referencing Obj-C classes
I'm currently working on moving one of our apps dependencies from Cocoapods to SPM. The dependency is written purely in Swift, but our codebase using it is both ObjC and Swift.
The problem I'm running into now is that anytime a class from the SPM library is defined in an ObjC class, it works, but if Swift tries to reference the property (from the ObjC class) it throws the error message: Value of type SwiftClass has no member libraryClass.
Before moving this package into SPM, Swift files had no issue referencing ObjC definitions of the librarys' classes. Now, anywhere in the app we try to do that the compiler doesn't have access to them.
The code structure looks something along the lines of this, stripped down to keep things minimalistic.
@objc
public class LibrarySwiftClass: NSObject {
etc etc
}
@interface ObjectiveCClass
@class LibrarySwiftClass;
@property (nonatomic, strong) LocalSwiftClass *localClass;
@property (nonatomic, strong) LibrarySwiftClass *libraryClass;
@end
extension ObjectiveCClass {
@objc
func checkPropertyValue() {
let testValue1 = self.localClass <----- This works correctly with no issue
let testValue2 = self.libraryClass <----- The above error happens here
}
}
NOTE: For this example the Swift class is an extension of the Objective C class, but there are other spots in the app where the Swift class isn't related to the ObjC class and they're still failing.
I put in breakpoints to check, and upon using self.value(forKey: "objCProperty")
in the swift class, it does show it correctly. Also, there are other non-SPM classes in the ObjC file that are able to properly be referenced with no issue.
I've tried including the ObjC files in the bridging header, and a couple other solutions to get the Swift file access to this property, with no luck. Seems like a very specific error case when setting up SPM. Anyone have any ideas?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|