Answer the question
In order to leave comments, you need to log in
How to add objects to favorites?
There is a pickerView, with the help of which I select an object (company stock) and display information about it.
I need to add a favorites button, I added it to the storyboard.
I can't figure out how to implement the functionality of the "favorites" button?
as a result, I want to make two buttons:
1) Add/remove from favorites with changing the picture on click
2) View a list of my favorite objects
If you have come across this, give a link to read how to do this.
That is, I have a dictionary, I need to create a container where I will put them on the click of a button, on the object selected in the picker.
Next, I need to create a second scene where I will view a list of my favorite objects.
Would such an approach be optimal?
object parsing:
func parseQuote(form data: Data) {
do {
let jsonObj = try JSONSerialization.jsonObject(with: data)
guard
let json = jsonObj as? [String: Any],
let companyName = json["companyName"] as? String,
let companySym = json["symbol"] as? String,
let price = json["latestPrice"] as? Double,
let priceChange = json["change"] as? Double else { return print("invalid")
}
DispatchQueue.main.async { [weak self] in
self?.displayStockInfo(companyName: companyName,
companySym: companySym,
price: price,
priceChange: priceChange)
}
} catch {
self.errorHandler(withTitle: "JSON error", andMessage: "error with json data: " + error.localizedDescription)
}
}
favoriteButton.setImage(UIImage(named: "star.png"), for: .normal)
Answer the question
In order to leave comments, you need to log in
So far I have added only one picture to the button, I did not find how to change it by pressing it.
I can't think of a way to implement the functionality of the "favorites" button?Understand, I also came from the exact sciences, from physics, and at school I was always "bad" in language. BUT, you need to write competently in Russian not because of grades, but in order to be understood correctly.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question