在警报中添加一些文本

时间:2017-08-05 08:09:12

标签: swift uialertcontroller

我有这些代码行:

let myAlert = UIAlertController(title: "Compiti trovati", message: "", preferredStyle: UIAlertControllerStyle.alert);     
let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default){ action in }
myAlert.addAction(okAction);
self.present(myAlert, animated: true, completion: nil);

如何在警报消息中放置后面的代码?

for index in 0...arr.count-1 {     
     print(MenuViewController.tasksArray[arr[index]].printTask())      
}

我想在警报的消息中显示数组arr[]的所有元素。 在数组中有2个元素:

[
   (104  -  Interrogazione  -  Fisica  -  10/08/2017  -  Yoloooooo)

   (115  -  Compito  -    -  10/08/2017  -  Commentoooooooo)
]

1 个答案:

答案 0 :(得分:1)

您可以使用

将字符串数组连接到单个String
let array = ["a", "b", "c"]
array.joined(separator: ", ") // -> "a, b, c"

要添加具有不同类型的异构数组,您必须将每个对象映射到字符串表示,它要求所有对象符合CustomStringConvertible

let array : [CustomStringConvertible] = [1, "b", Date()]
array.map{ $0.description }
     .joined(separator: ", ")