there was a similar problem: There is an object addinAprel in the class ViewController, also there is a class SecondController, it is necessary to transfer this object from one class to another in Swift.
Example programs:
Function in the ViewController class:
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
print("Selected item is", current_arr[row])
active_textField.text = current_arr[row]
let realm = try! Realm()
let events = realm.objects(EventsDB.self)
if ((text_field_months.text) == "Апрель")
{
if ((text_field_days.text) == "8")
{
let addinAprel=print(events.filter("dataMonth == %@ && dataDay ==%@",months_arr[3], days_arr[7]))
print("very good")
return addinAprel
}
if ((text_field_days.text) == "1")
{
let addinAprel=print(events.filter("dataMonth == %@ && dataDay ==%@",months_arr[3], days_arr[0]))
print("very good")
return addinAprel
}
print("good")
}
else{
print("very bad")
}
}
Class SecondController:
import Foundation
import UIKit
import RealmSwift
class SecondController: UIViewController, UITableViewDelegate {
let realm = try! Realm()
override func viewDidLoad() {
super.viewDidLoad()
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("You select \(massiv[indexPath.row])")
}
}