The error tells you that the class in question is only declared, but no definition is found. That happens, for example, if you declare a class with @class WKAlertAction
in a header because it is a parameter's type. As soon as you're trying to actually use that, though, ie send messages to the object in the implementation, you get this error, because the compiler can't find the actual definition of the class.
Without seeing your entire code I can't say for sure, but I guess you simply forgot to include the framework or module. Make sure you have the @import WatchKit;
somewhere in the relevant scope, ie probably in the implementation file you see the error in.
After checking with my another Watchos project, i found out the issue which i did.
i'm attaching images of target membership here.
As per the above error,My watchos project is selected in both watchos extension and ios extension. (WKAlertAction class in unavailable in ios and available in Watchos).
just i unchecked the target membership like this.
Now my WKAlertAction is working well.
i was searching for swift and this question popup so i will add the swift result that work for me while using
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])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.