Hi All. I am coding my first IOS App and have never coded before and am stuck on a crucial part.
The issue is that when the app is launched, a Dashboard is displayed to the User in the First View Controller.
- There is a field on the Dashboard that needs be retrieved from the Second View Controller.
- The field in the Second View Controller is the count of records from the mapViewDidFinishRenderingMap function.
- Note this is a Storyboard app, with a Tab Bar Controller
The question is: What is the best way for the First View Controller to retrieve the count from the rendered map in the Second View Controller so that the count is displayed on the Dashboard to the User upon launching the App?
Thanks in advance for any suggestions!
What is the best way for the First View Controller to retrieve the count from the rendered map in the Second View Controller so that the count is displayed on the Dashboard to the User upon launching the App?
It is hard to say what would the best for your app, as it depends on the details of your view controllers.
So, this is just one example, but you can use sort of shared data container. Something like this:
class DataContainer {
static let shared = DataContainer()
var countOfRecords: Int = 0
//...
}
class FirstViewController: UIViewController {
let dataContainer = DataContainer.shared
func someMethod() {
let count = dataContainer.countOfRecords
//...
}
}
class SecondViewController: UIViewController {
let dataContainer = DataContainer.shared
func someAction() {
//...
dataContainer.countOfRecords = ...
}
}