Home > Software design >  NSMutableArray objects string interpolation in SwiftUI Text View
NSMutableArray objects string interpolation in SwiftUI Text View

Time:01-10

I have a NSMutableArray, with multiple objects, and I want to print the name of the objects in a simple Swiftui.Text.

`myobject1.name="name1"

myobject2.name="name2"

myobject3.name="name3"

myArray[myObject1, myObject2, myObject3]`

How can I print all the names from the 3 objects in a single Text()?

Text(\(myArray.?))

I want my text to look like= "name1 name2 name3"

CodePudding user response:

let myArray = ["myObject1", "myObject2", "myObject3"]
    
var joined: String {
     myArray.joined(separator: "\n")
}
    
Text(joined)

enter image description here

var joined1: String {
    myArray.joined(separator: ", ")
}
Text(joined1)

enter image description here

  • Related