Seeing a weird export for iOS when I define a clas...
# multiplatform
g
Seeing a weird export for iOS when I define a class inheriting for another open one (or a sealed class). When I've this code:
Copy code
open class BaseClass(internal val internalVal: String)
class FooBar(val exposedVar: Int) : BaseClass("internalValue")
In Kotlin I only see one and only one FooBar constructor with the
Int
param. But the header from XCFramework exposes 2 constructors
Copy code
__attribute__((swift_name("BaseClass")))
@interface KmpTestBaseClass : KmpTestBase
- (instancetype)initWithInternalVal:(NSString *)internalVal __attribute__((swift_name("init(internalVal:)"))) __attribute__((objc_designated_initializer));
@end;

__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("FooBar")))
@interface KmpTestFooBar : KmpTestBaseClass
- (instancetype)initWithExposedVar:(int32_t)exposedVar __attribute__((swift_name("init(exposedVar:)"))) __attribute__((objc_designated_initializer));
- (instancetype)initWithInternalVal:(NSString *)internalVal __attribute__((swift_name("init(internalVal:)"))) __attribute__((objc_designated_initializer)) __attribute__((unavailable));
@property (readonly) int32_t exposedVar __attribute__((swift_name("exposedVar")));
@end;
I know I could make the BaseClass constructor private to avoid that export, but it doesn't feel adequate to exposes this 2nd constructor on FooBar anyway... What am I missing? Also I noticed the
unavailable
not sure what this means 😕
SSCCE : https://github.com/glureau/ksp-kmp-issues/tree/ios_constructors_export (For now I've no idea if it's my understanding or an issue somewhere.)
Looks like it's ok-ish, that's a way to mark a constructor usage as an error if you use them. Still I don't understand why we're exporting them. Is it not better to simply hide them?