Answer the question
In order to leave comments, you need to log in
How to select data from one array based on data from another?
Hello
Such task:
There is an array in which Int-s are stored, [0,2,3] for example.
There is a second array that stores objects of the Currency class [bc.Currency, bc.Currency, ...].
How can you derive an object from Currency based on an index that is equal to the value from an Int array?
For example: To display only objects whose index is 0, 2, 3.
Thank you in advance for your help!
Answer the question
In order to leave comments, you need to log in
Solved the problem
By creating two constants
let defaultData - passed an array containing Int indices
here let currencyData - passed an array containing class objects here
Then unpacked defaultData through for in and set it as an index value in currencyData.
func svodka () {
let defaultData = UserDefaults.standard.object(forKey: "Saved Default Selection") as? [Int]
let currencyData = currenciesArray
for item in defaultData! {
print (currencyData[item].codeOfCurrency)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question