Newbie question here. Using playground, I came up with the "logic" I wanted to use in my program. But don't know how to transfer the logic into my macOs Swift program. I have basically placed my text-transforming lines (from playground) inside a function, and now would like to call the function by using a button that would send the information into a TextView below it.
Here's my Content view:
struct ContentView: View {
@State private var myText: String = ""
func splitWords() {
var mystring = "Orange Apple Pear"
let mystringArray = mystring.components(separatedBy: " ")
for (_, niceword) in mystringArray.enumerated() {
print("<a id=\"\(niceword)\" class=\"ttTerm\" href=...>\(niceword)</a>") }
}
var body: some View {
VStack {
Button("Transformed text should go into field below", action: {
splitWords()
}
)
}
MultilineTextEditorView(text: $myText)
.frame(width: 400.0, height: 225.0)
.padding(30)
}
One main question here is -- I know I used "print" in playground to see the results in the console, but how do I make that line useful in terms of "printing" the data inside a TextView?
(I actually played around with different ideas in place of "print", like using "result" or assigning a "output" variable, but I kept getting errors.)
I have left out all the coding above this that deals with creating the TextView, which involves using "NSViewControllerRepresentable" -- but let me know if I should include that as well.
Thanks.