来自swift 2的swift 3更新语法

时间:2016-10-22 16:41:26

标签: swift syntax inout

在swift 2.2中的工作:

var messages = [JSQMessage]()

//...
for i in 1...10 {
 let sender = (i%2 == 0) ? "Server" : self.senderId
 let messageContent = "Message nr. \(i)"
 var message = JSQMessage(senderId: sender, displayName: sender, text: messageContent)
 self.messages += [message] //Cannot convert value of type '[JSQMessage]' to expected argument type 'inout_'
}
swift 3中的

给我错误。试图使用

self.messages += [&message] // Type of expression is ambiguous without more context

如何解决?

1 个答案:

答案 0 :(得分:0)

试试这个: self.messages.append(message)

有许多附加变体:

https://stackoverflow.com/a/24002784/1979882