Error Type 'String? 'has no member' default'

Asked 2 years ago, Updated 2 years ago, 38 views

let action=UIAlertController(title: "OK", message: .default) {(_)in

When I write, I get the error Type 'String?' has no member 'default' Why do I get this error?How can I fix the error?

swift

2022-09-30 14:27

1 Answers

Supplement the reason for the error.

The message for the argument is a value of type String?
https://developer.apple.com/documentation/uikit/uialertcontroller/1620106-message

Therefore, the compiler interprets String as omitted as follows:

UIAlertController (title: "OK", message: String.default)

However, there is no property (member variable) named default in the String type, so
The error String? type does not have the default member variable.

 type 'String?' has no member 'default'


2022-09-30 14:27

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.