0

When using SwiftUI's inflect parameter like this:

import SwiftUI

struct ContentView: View {
    @State  var count = 1
    
    var body: some View {
        VStack {
            VStack{
                
                Text("^[\(count) Song](inflect: true)")
                Button("Add"){ count += 1}
                Button("Remove"){ count -= 1}
            }
        }
        .padding()
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

Everything works as expected, but if we try to do these things, it does not:

import SwiftUI

struct ContentView: View {
    @State  var count = 1

    
    var body: some View {
        VStack {
            VStack{
                Text(generateString)
                Button("Add"){ count += 1}
                Button("Remove"){ count -= 1}
            }
        }
        .padding()
    }
}

func generateString(count:Int) -> String {
    return "^[\(count) Song](inflect: true)"
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}

I hope this is not so. If it is so, why is that?

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100

0 Answers0