Привет всем Я новичок в Realm, и у меня есть некоторые проблемы, чтобы представить некоторые ценности, которые мне нужны. У меня не было проблем с получением значений «name» для представления в tableView, но сейчас я пытаюсь получить доступ к значениям «phoneNumber» для помещения в текстовое поле получателя, но после многочисленных усилий я просто не могу понять, как это сделать получить доступ к значениям "phoneNumber". Я добавил фотографии и образцы своего проекта, надеюсь, я четко объяснил, любая помощь будет принята с благодарностью.
Проблема в "Отметить отправку SMS нажата"
import Foundation
import RealmSwift
class ContactInfo: Object {
@objc dynamic var name: String = ""
@objc dynamic var phoneNumber: String = ""
@objc dynamic var emailAddress: String = ""
}
import UIKit
import RealmSwift
import MessageUI
import ThirdPartyMailer
class SubscribersVC: UIViewController {
@IBOutlet weak var tableView: UITableView!
let realm = try! Realm()
let clients = ThirdPartyMailClient.clients()
var subscribers: Results<ContactInfo>?
var constant = Constants()
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
loadSubscribers()
}
//MARK: TO LOAD FROM REALM
func loadSubscribers() {
subscribers = realm.objects(ContactInfo.self)
subscribers = subscribers?.sorted(byKeyPath: "name", ascending: true)
tableView.reloadData()
}
@IBAction func postBtnPressed(_ sender: Any) {
// MARK: SEND SMS PRESSED
let smsAction = UIAlertAction(title: constant.sendSMS, style: .default) { (action) in
if MFMessageComposeViewController.canSendText() {
let controller = MFMessageComposeViewController()
controller.recipients = subscribers.
controller.messageComposeDelegate = self
self.present(controller, animated: true, completion: nil)
} else {
// MARK: Add UIAlert stating that "This device is not compatable for sending SMS"
print(Error.self, "This device is not compatable for sending SMS")
}
}
let emailAction = UIAlertAction(title: constant.sendEmail, style: .default) { (action) in
let client = ThirdPartyMailClient.init(name: "Yahoo Mail", URLScheme: "ymail", URLRoot: "//mail/compose", URLRecipientKey: "to", URLSubjectKey: "subject", URLBodyKey: "body")
let application = UIApplication.shared
if ThirdPartyMailer.application(application, isMailClientAvailable: client) {
_ = ThirdPartyMailer.application(application, openMailClient: client, recipient: self.constant.emailAddress.joined(separator: ","), subject: nil, body: nil)
} else {
print("\(String(describing: client)) is not available")
}
}
let cancelAction = UIAlertAction(title: "Cancel", style: .cancel) { (action) in
return
}
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
alert.addAction(smsAction)
alert.addAction(emailAction)
alert.addAction(cancelAction)
self.present(alert,animated: true) {
}
}
@IBAction func backBtnPressed(_ sender: Any) {
dismiss(animated: true, completion: nil)
}
}
//MARK: TableView Ext
extension SubscribersVC: UITableViewDelegate, UITableViewDataSource{
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return subscribers?.count ?? 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "namesCell")
if let subscriber = subscribers?[indexPath.row] {
cell!.textLabel?.text = subscriber.name
cell!.textLabel?.textColor = #colorLiteral(red: 1.0, green: 1.0, blue: 1.0, alpha: 1.0)
}
return cell!
}
}
extension SubscribersVC: MFMessageComposeViewControllerDelegate {
// MARK: Text Message Function
func messageComposeViewController(_ controller: MFMessageComposeViewController, didFinishWith result: MessageComposeResult) {
controller.dismiss(animated: true, completion: nil)
}
}