Я передаю объект Venue
из PreferencesVC
в DiscoverVC
, объявив экземпляр класса и установив переменную venue
для передаваемого объекта.
К моменту выполнения кода beginLoadView()
объект Venue
равен nil
и, следовательно, оператор if
некорректно выполняет
Вывод на консоль:
Class PreferencesVC: UIViewController{
@IBAction func doneBtnTapped(_ sender: Any) {
print("inside doneBtnTapped selectedVenue.name: \(selectedVenue?.name ?? "selectedVenue is nil")")
guard let discoverVC = storyboard?.instantiateViewController(withIdentifier: "DiscoverVC") as? DiscoverVC else { return }
discoverVC.venue = self.selectedVenue!
DataService.run.updateUserDiscoveryPreferences(forUID: Auth.auth().currentUser!.uid, discoverableBool: discoverable!, preferences: preferences) { (success) in
self.dismissDetail()
}
}//end func
}
Class DiscoverVC: UIViewController{
var venue: Venue?{
didSet{
print("DiscoverVC venue name: \(venue?.name ?? "venue name")")
}
}
override func viewWillDisappear(_ animated: Bool) {
print("inside viewWillDisappear")
venue = nil
}//end func
override func viewWillAppear(_ animated: Bool) {
print("inside viewWillAppear")
beginLoadView()
}
func beginLoadView(){
print("inside beginLoadView venue.name: \(venue?.name ?? "'venue' is nil")")
if venue != nil {
print("Venue var is not empty venue.name: \(String(describing: venue?.name))")
Utilities.run.showSVHUDWithStatus(uiView: self.view, status: "Discovering")
setupViews()
getCurrentLoggedUserProfile()
showHudAndStartUpdatingLocation()
observeUsersChanges()
} else {
print("Venue var is empty venue.name: \(String(describing: venue?.name))")
Utilities.run.showSVHUDWithStatus(uiView: self.view, status: "Discovering")
fetchNearestVenue()
getCurrentLoggedUserProfile()
}// end if-else
}//end func
}
}
Class VenueDetailsVC: UIViewController{
func presentDiscoverVC(){
guard let discoverVC = storyboard?.instantiateViewController(withIdentifier: "DiscoverVC") as? DiscoverVC else { return }
discoverVC.venue = self.venue!
discoverVC.showBackButton = true
DispatchQueue.main.async {
self.presentDetail(discoverVC)
}
}//end func
}