实际typealias' applicationContext'没有相应的预期声明

发布于 2025-01-17 14:45:54 字数 720 浏览 4 评论 0原文

我在尝试为 kotlin 多平台

Actual typealias 'ApplicationContext' has no corresponding expected declaration
The following declaration is incompatible because modality is different:
    public final expect class ApplicationContext

androidMain

import android.app.Application

actual typealias ApplicationContext = Application

commonMain

expect class ApplicationContext

iosMain

import platform.UIKit.UIView

actual typealias ApplicationContext = UIView

自定义上下文时遇到此问题在此处输入图像描述

I got this issue when trying to custom context for kotlin multiplatform

Actual typealias 'ApplicationContext' has no corresponding expected declaration
The following declaration is incompatible because modality is different:
    public final expect class ApplicationContext

androidMain

import android.app.Application

actual typealias ApplicationContext = Application

commonMain

expect class ApplicationContext

iosMain

import platform.UIKit.UIView

actual typealias ApplicationContext = UIView

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还给你自由 2025-01-24 14:45:54

期望类结构应与您要打字的类匹配。

Android的上下文类是摘要类,

public abstract class Context {}

因此模态错误来自那里。

您可能需要期望类是摘要,以解决该特定错误

expect abstract class ApplicationContext

abract>摘要将破坏uiview 不是摘要。因此,您要做的事情是直接的。

您需要考虑要实现目标的不同策略。

The expect class structure should match the class you're typealiasing to.

Android's context class is an abstract class

public abstract class Context {}

So the modality error comes from there.

You would need the expect class to be abstract as well to fix that particular error

expect abstract class ApplicationContext

Making it abstract would break modality for UIView as it's not abstract. So what you're trying to do is not possible in a straightforward manner.

You would need to think about a different strategy for what you're trying to achieve.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文