2017-08-05 12 views
0

我有几行代码:中加入一些文字警报

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) 
] 
+0

显然没有打印方法 – Marco

+0

普莱斯e添加数组内容和预期结果的示例。 – vadian

+0

这是内容:104 - Interrogazione - Fisica - 10/08/2017 - Yoloooooo 115 - Compito - - 10/08/2017 - 评论 – Marco

回答

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: ", ") 
+0

我编辑了这个问题,并且我有一个对象数组 – Marco

+0

我更新了答案 – vadian

+0

我必须在哪里放置该代码? – Marco