2017-08-05 42 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