I'm running into a problem where every function ma...
# kotlin-native
d
I'm running into a problem where every function marked with
suspend
isn't available in swift. In my example I created this fairly simple `UserRepository`:
Copy code
interface UserRepository {

    suspend fun getUser(uri: UserUri) : User

    suspend fun getUsers() : List<User>

    fun getUsersIosWorkaround() : List<User>
}
On jvm/android all three methods are available though when compiling for iOS the last non suspend function is available. This is the converted protocol as found in `common.h`:
Copy code
__attribute__((swift_name("UserRepository")))
@protocol CommonUserRepository
@required
- (NSArray<CommonUser *> *)getUsersIosWorkaround __attribute__((swift_name("getUsersIosWorkaround()")));
@end;
They're also missing on the dummy UserRepository implementation inside `common.h`:
Copy code
__attribute__((objc_subclassing_restricted))
__attribute__((swift_name("MockUserRepository")))
@interface CommonMockUserRepository : CommonBase <CommonUserRepository>
- (instancetype)init __attribute__((swift_name("init()"))) __attribute__((objc_designated_initializer));
+ (instancetype)new __attribute__((availability(swift, unavailable, message="use object initializers instead")));
- (NSArray<CommonUser *> *)getUsersIosWorkaround __attribute__((swift_name("getUsersIosWorkaround()")));
@end;
Presenters definied in
common
can invoke the suspend functions so I know they work in the PoC app. Not sure if this is a bug, bad configuration or by design.. so any help is appreciated!
a
Hello! This feature is unsupported by now, see in the documentation.
d
thanks... I though I read the whole page twice 🙈
s
You can still use those methods indirectly in Swift. You’ll need provide wrapper methods in Kotlin that use a callback interface. Beware that unless you’re using a special for of coroutines, your code will all need to run on the main thread.