Ask Your Question
4

When making an If statement in SwiftUI and attempting to add a Text element, why does the error message "Type '()' cannot conform to 'View'" occur?

asked 2023-06-15 03:35:24 +0000

plato gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2023-06-15 03:39:01 +0000

nofretete gravatar image

The error message occurs because the If statement is not returning a View. In Swift, the keyword '()' represents void or no return value. When an If statement does not have an else clause or is not returning a View from both if and else clauses, it will have type '()'. To fix the error, make sure both if and else clauses return a View.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-15 03:35:24 +0000

Seen: 8 times

Last updated: Jun 15 '23