Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 3843
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 3, 20222022-06-03T04:03:03+00:00 2022-06-03T04:03:03+00:00

swift – Xcode – swiftui: Type ‘()’ cannot conform to ‘View’

  • 0

[ad_1]

I don’t get it, why i can’t have a simple if/else statement in the view of my body. Basically in this view there will be other views placed into a scrollView, but only if the depending boolean is true – that was the plan. But I get a “Type ‘()’ cannot conform to ‘View'” error message on the “if showFurtherContent {…” line (marked with **). I know, that views aren’t made for logic – but I have no clue, why I can’t put a simple if/else statement in there to create view elements – that should be possible in my opinion. Can someone help me out, how to achieve this? The application will be a chatbot and the boolean for visualizing different “modules” (basically other SwiftUI View files) should let the view place it, if true. Otherwise I can’t figure out, how to dynamically fill a scrollView with different ui elements – the swiftui is currently driving me crazy but plz note: im still learning it but I thought such simple things should be easily possible.

struct ChatBot: View {

@State var _ratio = 60.0;
@State var _start : Bool = false;

@State private var messageText = ""
@State var messages: [String] = [""]
@State public var messageProperty = "Y"

@State private var botWriting = false
@State private var textInputEnabled = false

@ObservedObject var vm = MainMessagesViewModel() //reference to MMVM

@StateObject var cbl = ChatBotVariables()
@State var _case: String = "text"
//&@EnvironmentObject var cbl: ChatBotVariables

@State var showFurtherContent: Bool = false

init() {
    initChatbot()
}

var body: some View {
    
   NavigationView {
       VStack {
           
           Button{
               showFurtherContent.toggle()
               //switchHappyBar() // Debug
           }label:{
               Image(systemName: "trash")
           }
           
           ScrollView{
             
               ForEach(messages, id: \.self){ message in
                   if message.contains("[USER]"){
                       let newMessage = message.replacingOccurrences(of:"[USER]", with: "")
                       
                       HStack{
                           Spacer()
                           Text(newMessage)
                               .padding()
                               .foregroundColor(Color.white)
                               .background(.blue.opacity(0.8))
                               .cornerRadius(10)
                               .padding(.horizontal, 16)
                               .padding(.bottom, 10)
                       }
                   }else{
                       
                       HStack{
                           Text(message)
                               .padding()
                               .background(.gray.opacity(0.15))
                               .cornerRadius(10)
                               .padding(.horizontal, 16)
                               .padding(.bottom, 10)
                           
                           Spacer()
                       }
                       
                       HStack{
                           
                           **if showFurtherContent {**
                               ChatBot_EmojiBar()
                               showFurtherContent.toggle()
                           }else{
                               ChatBot_Answer()
                           }
                       }
                     
                   }
               }//.rotationEffect(.degrees(180))
               
               /*
               if cbl.showFurtherContent {
                   
                   switch cbl.answerCase{
                        case "emoji":
                            ChatBot_EmojiBar()
                        break;
                        case "video":
                            ChatBot_EmojiBar()
                        break;
                        case "yesno":
                            ChatBot_Answer()
                           break;
                        default:
                           ()
                        break;
                   }
                   cbl.showFurtherContent.toggle()
               }*/
                
           }//.rotationEffect(.degrees(180))
           .background(Color.gray.opacity(0.05))

           if(messages.count > 1){
               let mCount = messages.count
               Text("count: \(mCount) answer: \(cbl.answerCase) Property: \(messageProperty)")
           }
           
           HStack {
               if botWriting{
                   Image(systemName: "ellipsis.bubble.fill")
                       .font(.system(size: 26))
                       .foregroundColor(Color.blue)
               }
           }

[..] further code but not relevant

[ad_2]

  • 0 0 Answers
  • 27 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 8038 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 1840 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 1920 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.