英文:
NSMutableArray objects string interpolation in SwiftUI Text View
问题
我有一个NSMutableArray,其中包含多个对象,我想在一个简单的SwiftUI.Text中打印这些对象的名称。
myobject1.name = "name1"
myobject2.name = "name2"
myobject3.name = "name3"
myArray = [myObject1, myObject2, myObject3]
如何在一个Text()中打印这3个对象的所有名称?
Text("\(myArray.map { $0.name }.joined(separator: "+"))")
我希望我的文本看起来像这样:"name1+name2+name3"
英文:
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"
答案1
得分: 0
让我们开始翻译:
let myArray = ["myObject1", "myObject2", "myObject3"]
var joined: String {
myArray.joined(separator: "\n")
}
Text(joined)
var joined1: String {
myArray.joined(separator: ", ")
}
Text(joined1)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论