簡體   English   中英

類消息的接收器類型“WkAlertAction”是前向聲明

[英]Receiver type "WkAlertAction" for class message is a forward declaration

在我的 watchos 應用程序中,我正在嘗試使用 WkAlertAction,但遇到了這個問題。我附上了快照以供參考。

類消息的接收器類型“WkAlertAction”是前向聲明

這是什么意思? 我究竟做錯了什么?

在此處輸入圖片說明

該錯誤告訴您僅聲明了有問題的類,但未找到定義。 例如,如果您在標頭中使用@class WKAlertAction聲明一個類,因為它是參數的類型,就會發生這種情況。 但是,一旦您嘗試實際使用它,即向實現中的對象發送消息,就會收到此錯誤,因為編譯器找不到該類的實際定義。

沒有看到你的整個代碼,我不能肯定地說,但我猜你只是忘記了包含框架或模塊。 確保你有@import WatchKit; 在相關范圍內的某個地方,即可能在您看到錯誤的實現文件中。

在檢查了我的另一個 Watchos 項目后,我發現了我所做的問題。

我在這里附上目標會員的圖片。

在此處輸入圖片說明

根據上面的錯誤,我的watchos項目在watchos擴展和ios擴展中都被選中了。 (WKAlertAction 類在 ios 中不可用,在 Watchos 中可用)。

只是我像這樣取消了目標成員資格。

在此處輸入圖片說明

現在我的 WKAlertAction 運行良好。

我正在搜索 swift 並彈出這個問題,所以我會在使用時添加對我有用的 swift 結果

WKAlertAction

手表操作系統 4.0

斯威夫特 4

        let action1 = WKAlertAction.init(title: "Cancel", style:.cancel) {
            print("cancel action")
        }
        
        let action2 = WKAlertAction.init(title: "default", style:.default) {
            print("default action")
        }
        
        let action3 = WKAlertAction.init(title: "destructive", style:.destructive) {
            print("destructive action")
        }
        
        presentAlert(withTitle: "Alert Title", message: "message is here", preferredStyle:.actionSheet, actions: [action1,action2,action3])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM