Hi i have a issue with implementing interface from...
# multiplatform
b
Hi i have a issue with implementing interface from Kotlin in Swift
Copy code
interface GoogleSignInPlatform {
    suspend fun signIn(): GoogleSignInResult

    suspend fun signOut(): Boolean

    fun isSignedIn(): Boolean

    suspend fun getCurrentUser(): GoogleUserInfo?
}
Can i get some help here
🧵 4
I am getting this error
c
Please don’t post long code snippets to the main thread. Move them in here please!
b
This is my interface
Copy code
import Foundation
import GoogleSignIn
import UIKit
import ComposeApp

// This class implements the GoogleSignInPlatform interface from Kotlin
class GoogleSignInBridge: GoogleSignInPlatform {
  func getCurrentUser(completionHandler: @escaping (GoogleUserInfo?, (any Error)?) -> Void) {
    guard let currentUser = GIDSignIn.sharedInstance.currentUser else {
      completionHandler( nil , nil)
    }
     
    // Extract user information
    let userId = currentUser.userID ?? ""
    let email = currentUser.profile?.email ?? ""
    let displayName = currentUser.profile?.name ?? ""
    let photoUrl = currentUser.profile?.imageURL(withDimension: 200)?.absoluteString
    let idToken = currentUser.idToken?.tokenString
     
    // Create and return GoogleUserInfo
    completionHandler( GoogleUserInfo(
      userId: userId,
      email: email,
      displayName: displayName,
      photoUrl: photoUrl,
      idToken: idToken
    ),nil)
  }
   
  func getCurrentUser() async throws -> GoogleUserInfo? {
    guard let currentUser = GIDSignIn.sharedInstance.currentUser else {
      return nil
    }
     
    // Extract user information
    let userId = currentUser.userID ?? ""
    let email = currentUser.profile?.email ?? ""
    let displayName = currentUser.profile?.name ?? ""
    let photoUrl = currentUser.profile?.imageURL(withDimension: 200)?.absoluteString
    let idToken = currentUser.idToken?.tokenString
     
    // Create and return GoogleUserInfo
    return GoogleUserInfo(
      userId: userId,
      email: email,
      displayName: displayName,
      photoUrl: photoUrl,
      idToken: idToken
    )
  }
   
  func signIn(completionHandler: @escaping (GoogleSignInResult?, (any Error)?) -> Void) {
    guard let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,
       let rootViewController = windowScene.windows.first?.rootViewController else {
       
      completionHandler(GoogleSignInResult(
        isSuccess: false,
        userInfo: nil,
        errorMessage: "No root view controller found"
      ), nil)
    }
     
     
    GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController){ result, error in
      if let user = result?.user {
        let userId = user.userID ?? ""
        let email = user.profile?.email ?? ""
        let displayName = user.profile?.name ?? ""
        let photoUrl = user.profile?.imageURL(withDimension: 200)?.absoluteString
        let idToken = user.idToken?.tokenString
         
        // Create GoogleUserInfo
        let userInfo = GoogleUserInfo(
          userId: userId,
          email: email,
          displayName: displayName,
          photoUrl: photoUrl,
          idToken: idToken
        )
         
        // Return successful result
        completionHandler(GoogleSignInResult(
          isSuccess: true,
          userInfo: userInfo,
          errorMessage: nil
        ), nil)
      }
    }
     
     
  }
   
  func signIn() async throws -> GoogleSignInResult {
    guard let windowScene = await UIApplication.shared.connectedScenes.first as? UIWindowScene,
       let rootViewController = await windowScene.windows.first?.rootViewController else {
      return GoogleSignInResult(
        isSuccess: false,
        userInfo: nil,
        errorMessage: "No root view controller found"
      )
    }
     
    do {
      // Attempt to sign in
      let result = try await GIDSignIn.sharedInstance.signIn(withPresenting: rootViewController)
       
      // Extract user information
      let user = result.user
      let userId = user.userID ?? ""
      let email = user.profile?.email ?? ""
      let displayName = user.profile?.name ?? ""
      let photoUrl = user.profile?.imageURL(withDimension: 200)?.absoluteString
      let idToken = user.idToken?.tokenString
       
      // Create GoogleUserInfo
      let userInfo = GoogleUserInfo(
        userId: userId,
        email: email,
        displayName: displayName,
        photoUrl: photoUrl,
        idToken: idToken
      )
       
      // Return successful result
      return GoogleSignInResult(
        isSuccess: true,
        userInfo: userInfo,
        errorMessage: nil
      )
    } catch {
      // Return error result
      return GoogleSignInResult(
        isSuccess: false,
        userInfo: nil,
        errorMessage: error.localizedDescription
      )
    }
  }
   
  func signOut(completionHandler: @escaping (KotlinBoolean?, (any Error)?) -> Void) {
    GIDSignIn.sharedInstance.signOut()
    completionHandler(KotlinBoolean(bool: true), nil)
  }
   
  func signOut() async throws -> KotlinBoolean {
    GIDSignIn.sharedInstance.signOut()
    return KotlinBoolean(bool: true)
  }
   
  func isSignedIn() -> KotlinBoolean {
    let isSignedIn = GIDSignIn.sharedInstance.hasPreviousSignIn()
    return KotlinBoolean(bool: isSignedIn)
  }
   
}
This is my swift code
@Chrimaeon done
b
Can I get some help here 🥺