i am new in swift and my question maybe confuse you but i try to explaine that clearly. i want make weather app. that i have one view controller in my story. in my view controller, i have 2 view that i make them in seperate xib file. one view has a label for show the name and a imageview for show the condition weather of the selected city and another view is collection view that show many city for selecting. i save my city information in a class and make a model for city. this is my model file:
struct City {
private(set) public var code: String
private(set) public var fName: String
private(set) public var eName: String
private(set) public var image: String
init (code: String, fName: String, eName: String, image: String) {
self.code = code
self.fName = fName
self.eName = eName
self.image = image
}
}
and below code is my class that i save many city info in array;
public class Publics {
static let instance = Publics()
private let Cities = [
City(code: "143127", fName: "a", eName: "A", image: "https://media.is48.jpg/3") ,
City(code: "143083", fName: "b", eName: "B", image: "http://www.ie_650_365.jpg") ,
City(code: "121801", fName: "c", eName: "C", image: "https://www.weeeh.jpg?13112") ,
City(code: "418863", fName: "d", eName: "D", image: "https://i.pinf7c0ec2c8617.jpg")
]
}
i show my array in collection City correctly, now i want when i select one city, the eName and image of my selected city show in label and imageview of first view. i write below code for save selected city information in "city" var but i dont know how can i send this info to another file:
var city = City(code: "", fName: "", eName: "", image: "")
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
city = Publics.instance.getCities()[indexPath.row]
}
what should i do? (im sorry for long description)