0

Seems Xcode 13 SwiftUI does not support + operator. For example

Text("Not you? Hit the")
                        + Text(" ‘Back’ ").fontWeight(.bold)
                        + Text("arrow and use a different email.")

Because of an error of

ambiguous operator declarations found for operator

----------------------------------------

CompileDylibError: Failed to build WarningRedirectToLoginView.swift

Compiling failed: ambiguous operator declarations found for operator

/Users/liang.wang.cm/Documents/Project/Demo-IOS/Demo/View/Login/WarningRedirectToLoginView.swift:23:192: error: ambiguous operator declarations found for operator
                    Text(__designTimeString("#6206.[1].[2].property.[0].[0].arg[0].value.[0].arg[2].value.[1].arg[0].value.[0].[0]", fallback: "Looks like you already have an account for ")) +
                                                                                                                                                                                               ^
Swift.:1:16: note: found this matching operator declaration
infix operator + : AdditionPrecedence
               ^
Demo_Dev.:1:16: note: found this matching operator declaration
infix operator + : DefaultPrecedence
               ^

LiangWang
  • 8,038
  • 8
  • 41
  • 54
  • Can't duplicate the issue. Xcode 13.3.1. Are you sure there is not some hidden character in between? – Yrb May 05 '22 at 01:26

1 Answers1

0

you can add Text together in SwiftUI. Here is an example that works for me: make sure the spacing is correct, (blank space (or more) before + blank space (or more) after). You can also use a HStack

struct ContentView: View {
    var body: some View {
        Text("Not you? Hit the") + Text(" ‘Back’ ").fontWeight(.bold) + Text("arrow and use a different email.")
        
        HStack {
            Text("text1").foregroundColor(.green)
            Text(" text2 ").foregroundColor(.blue)
            Text("text3").foregroundColor(.red)
        }
    }
}

Note the error seems to indicate that you have declared a + operator for your own purpose. The compiler may be confused about that.