我已經構建了一個使用核心數據並可以發送短信的小應用程序。現在在發送短信部分,它一直告訴我下面的一個「messageVC.recipients = items」有錯誤「無法將[NSManagedObject]類型的值指定爲鍵入[String]。 items是一個NSManagedObject的數組並存儲電話號碼。 我已經嘗試過messageVC.recipients = items.Stringvalue,messageVC.recipients = items as! [String],messageVC.recipients = items.valueforkey [「phonenumeb」] as?字符串,它不能工作。請幫忙。 非常感謝。如何糾正錯誤「無法指定[NSManagedObject]類型的值鍵入[String]
@IBAction FUNC sendCurrentLocSms(發件人:AnyObject){
let messageVC = MFMessageComposeViewController()
messageVC.body = "My address is " + "\(myAddress.text!) " + ". " + "My GPS is " + "\(myLat.text!)" + "," + "\(myLong.text!)"
messageVC.subject = "Attention!"
messageVC.recipients = items
messageVC.messageComposeDelegate = self
self.presentViewController(messageVC, animated: false, completion: nil)
}
謝謝MirekE。我試圖按你的方式。但它表示「NSManagedObject類型的值沒有電話號碼的成員」。我的實體是「聯繫人」,唯一的屬性是「電話號碼」。它是一個字符串var items = [NSManagedObject](),位於開頭 – nycwondering
,謝謝MirekE。在其他專家的幫助下,以下工作。 messageVC.recipients = items.map { 返回$ 0.valueForKey(「phonenumber」)as!串} – nycwondering