Reputation: 726
In my watchos app,i'm trying to use WkAlertAction but am getting this issue.I have attached snapshot for reference.
What does it mean? What am I doing wrong?
Upvotes: 2
Views: 1569
Reputation: 3831
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])
Upvotes: 0
Reputation: 726
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.
Upvotes: 1
Reputation: 4424
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, i.e. 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, i.e. probably in the implementation file you see the error in.
Upvotes: 1