Mohammed Akram Hussain
08/11/2023, 11:18 AMabstract class FacebookAnalytics {
@NativeCoroutines
abstract suspend fun logEvent(event: String, properties: Map<String, String>)
}
public class TestFacebookAnalyticsWriter : FacebookAnalytics {
public override func logEvent(event: String, properties: [String : String]) -> (@escaping (KotlinUnit, KotlinUnit) -> KotlinUnit, @escaping (Error, KotlinUnit) -> KotlinUnit, @escaping (Error, KotlinUnit) -> KotlinUnit) -> () -> KotlinUnit {
print("FacebookAnalytics: logEvent()")
AppEvents.shared.logEvent(AppEvents.Name(event), parameters: properties)
}
}
And then I want to call this Analytics as such:
let analytics = TestFacebookAnalyticsWriter()
try! await asyncFunction(for: analytics.logEvent(event: "", properties: ["" : ""]))
But I don’t know what to return from the TestFacebookAnalyticsWriter logEvent functionMohammed Akram Hussain
08/11/2023, 11:18 AMRick Clephas
08/11/2023, 11:31 AMMohammed Akram Hussain
08/11/2023, 12:48 PMMohammed Akram Hussain
08/11/2023, 1:10 PMasyncFunction
I should still be able to override the logEvent method right?Rick Clephas
08/11/2023, 1:14 PMlogEvent
function it won’t have the desired effect as long as the function is annotated with @NativeCoroutines
.
When you override the logEvent
function from your Swift application you would actually be overriding the generated extension from KMP-NativeCoroutines.Rick Clephas
08/11/2023, 1:17 PMfun FacebookAnalytics.logEventNative(event: String, properties: Map<String, String>) = nativeSuspend {
logEvent(event, properties)
}
Which should allow you to override logEvent
and use logEventNative
with the asyncFunction(for:)
helper.
However please keep in mind that just overriding logEvent
won’t support cancellation of the suspend/async function.