I passed data from ViewController1
to ViewController2
via segue, but how can I send data to the Class
? This class is not a ViewController.
ViewController1
has aUIPickerView
that gives the data (String).The String will complete an URL needed in
ViewController2
.
Class
class A: SendDataFromDelegate {
func sendData(data: String) {
self.data = data
}
var delegate : SendDataFromDelegate?
ViewController1
@IBAction func Picker(_ sender: Any) {
var delegate: SendDataFromDelegate?
delegate?.sendData(data: data)
}
protocol SendDataFromDelegate {
func sendData(data : String)
}
Is this a good way to do it?
Or should I create all the possible URLs in the class
, and call them from ViewController2
?