【问题标题】:I got error on Xcode7 for String我在 Xcode7 上遇到 String 错误
【发布时间】:2016-01-30 10:23:12
【问题描述】:

错误是“无法将类型'[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)
}

【问题讨论】:

  • 你的代码中的 Const 是什么?
  • 这一行需要预期的类型Const.CONTACT_MAIL
  • 你应该只传递字符串
  • 喜欢(Const.String)?代码应该是什么样子?

标签: ios swift


【解决方案1】:

setToRecipients 需要一个字符串数组。 Apple 文档给出了这个例子

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

【讨论】:

  • 如果你喜欢这个答案,你需要勾选它以鼓励人们提供帮助:-)
【解决方案2】:

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

picker.setToRecipients([Const.CONTACT_MAIL])

这是因为它需要一个数组

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-23
    • 1970-01-01
    • 2012-04-08
    • 2019-06-13
    • 2019-03-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-11
    相关资源
    最近更新 更多