我有这几行代码:

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[]的所有元素。
数组中有两个元素:
[
   (104  -  Interrogazione  -  Fisica  -  10/08/2017  -  Yoloooooo)

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

最佳答案

您可以使用

let array = ["a", "b", "c"]
array.joined(separator: ", ") // -> "a, b, c"

要添加具有不同类型的异类数组,您必须将每个对象映射到字符串表示,它要求所有对象都符合String
let array : [CustomStringConvertible] = [1, "b", Date()]
array.map{ $0.description }
     .joined(separator: ", ")

关于swift - 在警报中添加一些文本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45519746/

10-14 21:00
查看更多