Home Moving an object from one class to another in Swift
Reply: 0

Moving an object from one class to another in Swift

user1610
1#
user1610 Published in July 23, 2018, 3:53 am

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])")

}
}
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312213 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO