Friday, August 19, 2022
HomeiOS Developmentios - Unable to entry SPM courses in Swift courses referencing Obj-C...

ios – Unable to entry SPM courses in Swift courses referencing Obj-C courses

[ad_1]

I am at present engaged on shifting one in every of our apps dependencies from Cocoapods to SPM. The dependency is written purely in Swift, however our codebase utilizing it’s each ObjC and Swift.

The issue I am operating into now could be that anytime a category from the SPM library is outlined in an ObjC class, it really works, but when Swift tries to reference the property (from the ObjC class) it throws the error message: Worth of sort SwiftClass has no member libraryClass.

Earlier than shifting this bundle into SPM, Swift recordsdata had no subject referencing ObjC definitions of the librarys’ courses. Now, anyplace within the app we strive to do this the compiler would not have entry to them.

The code construction seems one thing alongside the strains of this, stripped all the way down to preserve issues minimalistic.

@objc
public class LibrarySwiftClass: NSObject {
    and so on and so on
}
@interface ObjectiveCClass
@class LibrarySwiftClass;
@property (nonatomic, robust) LocalSwiftClass *localClass;
@property (nonatomic, robust) LibrarySwiftClass *libraryClass;
@finish
extension ObjectiveCClass {
    @objc
    func checkPropertyValue() {
         let testValue1 = self.localClass    <----- This works accurately with no subject
         let testValue2 = self.libraryClass   <----- The above error occurs right here
    }
}

NOTE: For this instance the Swift class is an extension of the Goal C class, however there are different spots within the app the place the Swift class is not associated to the ObjC class they usually’re nonetheless failing.

I put in breakpoints to verify, and upon utilizing self.worth(forKey: "objCProperty") within the swift class, it does present it accurately. Additionally, there are different non-SPM courses within the ObjC file which are in a position to correctly be referenced with no subject.

I’ve tried together with the ObjC recordsdata within the bridging header, and a pair different options to get the Swift file entry to this property, with no luck. Looks as if a really particular error case when organising SPM. Anybody have any concepts?

[ad_2]

RELATED ARTICLES

Most Popular

Recent Comments