i have these classes :
class Song {
var title : String = ""
weak var album : Album?
init() {
self.album = Album()
}
}
and
class Album {
var title : String = ""
var Songs : Array < Song > = []
deinit {
print(self , self.title)
}
}
this should works fine but whenever i try to set title for album from a song instance i get nil error for album for example if execute code below :
let s = Song()
s.title = "some title for song"
s.album!.title = "some title for album"
when trying to s.album!.title = "" i get :
unexpectedly found nil while unwrapping an Optional value
deinit function called on init in Song class once
what am i doing wrong here? how should i fix this?