我在Xcode7 for String上遇到错误

时间:2016-01-30 10:23:12

标签: ios swift

错误是"无法转换类型' [AnyObject]'预期参数类型' [String]?'"。有谁知道如何解决这个问题?

   func send() {
    let picker = MFMailComposeViewController()
    picker.mailComposeDelegate = self
    picker.setSubject(subject.text!)
     //the code below is the reason I got error for
    picker.setToRecipients(Const.CONTACT_MAIL)
    picker.setMessageBody(body.text, isHTML: true)
    presentViewController(picker, animated: true, completion: nil)
}

2 个答案:

答案 0 :(得分:1)

setToRecipients期待一个字符串数组。 Apple文档提供了此示例

picker.setToRecipients(["address@example.com"])

答案 1 :(得分:0)

如果Const.CONTACT_MAIL是一个字符串,那么你可以试试这个:

picker.setToRecipients([Const.CONTACT_MAIL])

这是因为它需要一个数组