Robert Munro
10/10/2022, 12:04 PMdomainKmm
class LoginUseCase {
sealed class State {
object Initial : State()
object StartAuthorization : State()
object AuthorizationTokenReceived : State()
object AccessTokenReceived : State()
object SuppliersLoading : State()
data class SuppliersLoaded(val suppliers: List<Supplier>) : State()
data class ConfirmSupplierChange(val chosenSupplier: Supplier, val currentSupplier: Supplier) : State()
data class SupplierLoadError(val e: Throwable) : State()
object NoSupplier : State()
data class LoggedInSuccess(val isNewSupplier: Boolean) : State()
}
}
So i can use DomainKmmLoginUseCase
and DomainKmmLoginUseCase.State
but i cant use DomainKmmLoginUseCase.State.Initial
I cant find any declaration of things like Initial
or StartAuthorization
in the generated iOS header file.
is there any guidance on using sealed classes in iOS? i've seen they dont really map to swift well - but havent been able to find any usage examples.novikau
10/11/2022, 10:07 AMInitial
is not declared as internal
it should be generated as DomainKmmLoginUseCase.StateInitial
(without a dot between State
and Initial
) in the iOS header file. But you're right, the sealed classes are mapped to swift as regular classes, so you will loose the restricted class hierarchy of the sealed classes when you work with these classes in swift.Robert Munro
10/11/2022, 11:55 AMDomainKmmLoginUseCase.State
with no subclasses. I get all the member `fun`s of LoginUseCase
- so for some reason its not generating the children of the sealed State
class. I'm on 1.6.20.novikau
10/11/2022, 12:39 PMso i just getforwith no subclasses.DomainKmmLoginUseCase.State
Initial
class (a subclass of State
sealed class) you should use DomainKmmLoginUseCase.StateInitial
. At least this is how I see it is generated in my case for the nested classes of a 3d level. I'm on 1.7.0, so maybe something has been changed in the latest updates.Robert Munro
10/11/2022, 1:05 PMDomainKmmLoginUseCase.StateInitial
doesn't get generated for me.novikau
10/11/2022, 2:07 PMLoginUseCase
where does DomainKmmLoginUseCase
come from?Robert Munro
10/11/2022, 2:42 PMLoginUseCase
swift its DomainKmmLoginUseCase
novikau
10/11/2022, 2:56 PM__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("LoginUseCase")))
@interface CSCLoginUseCase : CSCBase
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
@end;
__attribute__((swift_name("LoginUseCase.State")))
@interface CSCLoginUseCaseState : CSCBase
@end;
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("LoginUseCase.StateInitial")))
@interface CSCLoginUseCaseStateInitial : CSCLoginUseCaseState
+ (instancetype)alloc __attribute__((unavailable));
+ (instancetype)allocWithZone:(struct _NSZone *)zone __attribute__((unavailable));
+ (instancetype)initial __attribute__((swift_name("init()")));
@property (class, readonly, getter=shared) CSCLoginUseCaseStateInitial *shared __attribute__((swift_name("shared")));
@end;
So there is a module prefix in the generated class name, but only for Objective C. For swift there is a different name defined (without a prefix) and I can access the kotlin classes from swift code by this name.Robert Munro
10/11/2022, 4:49 PMdomainKmm
is included via sharedKmm
- as there classes are created via Koin).
I omitted the methods in the class above for brevity. This is what i get though..
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("DomainKmmLoginUseCase")))
@interface SharedKmmDomainKmmLoginUseCase : SharedKmmBase
- (instancetype)initWithAuthStateManager:(id<SharedKmmDomainKmmIAuthStateManager>)authStateManager authChecks:(id<SharedKmmDomainKmmUserAuthorizationChecker>)authChecks jwtTokenParser:(SharedKmmDomainKmmJwtTokenParser *)jwtTokenParser userMapper:(SharedKmmDomainKmmUserMapper *)userMapper prefs:(SharedKmmDomainKmmAppPreferences *)prefs analytics:(SharedKmmDomainKmmAnalytics *)analytics supplierApiGatewayRepository:(id<SharedKmmDomainKmmSupplierApiRepository>)supplierApiGatewayRepository newLoggedInUserUseCase:(SharedKmmDomainKmmNewLoggedInUserUseCase *)newLoggedInUserUseCase networkErrorBus:(id<SharedKmmDomainKmmINetworkErrorBus>)networkErrorBus __attribute__((swift_name("init(authStateManager:authChecks:jwtTokenParser:userMapper:prefs:analytics:supplierApiGatewayRepository:newLoggedInUserUseCase:networkErrorBus:)"))) __attribute__((objc_designated_initializer));
- (SharedKmmDomainKmmLoginUseCaseState *)_getState __attribute__((swift_name("_getState()")));
possibly if i include domainKmm
directly it might work - I guess that would be a bug tho. not sure.LoginUseCase
to the sharedKmm
module and the sealed classes generate OK.
Does this seem like a bug?novikau
10/11/2022, 6:57 PM