I have the following code in my class MemeMeViewModel which is an ObservableObject :
@Published var memes: [MemeMeModel.Meme] = retreiveFromArrayOfMeme()
func retreive() -> [(UIImage, String)] {
var temp = [(UIImage, String)]()
if let Memes = UserDefaults.standard.object(forKey: "MemesList") as? [[Any]] {
for Meme in Memes {
if let image = UIImage(data: Meme[0] as! Data) {
temp.append((image, Meme[1] as! String))
}
}
}
return temp
}
func retreiveFromArrayOfMeme() -> [MemeMeModel.Meme] {
var temp = [MemeMeModel.Meme]()
if let Memes = UserDefaults.standard.object(forKey: "MemesList") as? [[Any]] {
for Meme in Memes {
temp.append(MemeMeModel.Meme(pngRepresentation: Meme[0] as! Data, content: Meme[1] as! String))
}
}
return temp
}
On line 1, I have the following error : "Cannot use instance member 'retreiveFromArrayOfMeme' within property initializer; property initializers run before 'self' is available".
I don't know what to do ... Need help please !