https://kotlinlang.org logo
#multiplatform
Title
# multiplatform
j

jean

09/01/2020, 3:23 PM
I have this data class in my shared module
Copy code
import kotlinx.serialization.Serializable

@Serializable
data class News(
    val type: String,
    val title: String,
    val image: String,
    val link: String,
    val date: String
)
From Xcode, I see it like this after importing the framework
Copy code
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("News")))
@interface SharedCodeNews : SharedCodeBase
- (instancetype)initWithType:(NSString *)type title:(NSString *)title image:(NSString *)image link:(NSString *)link date:(NSString *)date __attribute__((swift_name("init(type:title:image:link:date:)"))) __attribute__((objc_designated_initializer));
- (NSString *)component1 __attribute__((swift_name("component1()")));
- (NSString *)component2 __attribute__((swift_name("component2()")));
- (NSString *)component3 __attribute__((swift_name("component3()")));
- (NSString *)component4 __attribute__((swift_name("component4()")));
- (NSString *)component5 __attribute__((swift_name("component5()")));
- (SharedCodeNews *)doCopyType:(NSString *)type title:(NSString *)title image:(NSString *)image link:(NSString *)link date:(NSString *)date __attribute__((swift_name("doCopy(type:title:image:link:date:)")));
- (BOOL)isEqual:(id _Nullable)other __attribute__((swift_name("isEqual(_:)")));
- (NSUInteger)hash __attribute__((swift_name("hash()")));
- (NSString *)description __attribute__((swift_name("description()")));
@property (readonly) NSString *date __attribute__((swift_name("date")));
@property (readonly) NSString *image __attribute__((swift_name("image")));
@property (readonly) NSString *link __attribute__((swift_name("link")));
@property (readonly) NSString *title __attribute__((swift_name("title")));
@property (readonly) NSString *type __attribute__((swift_name("type")));
@end;
I try to instantiate it from swift
var news = News()
but I get the error
init() is not available
and if I start to add arguments like
News(type: "a type")
then I get
argument passed to call that takes no arguments
Figured that one too with my ios coworker : we had to create a bridge header file and add it to the swift compiler settings
3 Views