“for each” loop with coding object

Hi

 

how can i count or make an for each loop over an codable object?

 

for example this is my coding object:

struct ApiBalanceAnswer: Codable {
    let status: String
    let data: Detail
    let id: String
    let ok: String

    struct Detail: Codable{
        let balance: balance
        let obalance: obalance
        let time: Int
  
        struct balance: Codable{
            let USD: String
            let EUR: String
            let GBP: String
            let RUB: String


        }
        struct obalance: Codable{
            let USD: String
            let EUR: String
            let GBP: String
            let RUB: String

        }
    }
}

 

i have parsed the date from an API request this works without any problem.

(this exapmle contains just sonme of the currencies)

 

now i wanna show for each currency the details in an label.

for that i need an for each loop but if i try it (as example):

for (key, value) in balance!.data.balance {
...
}

or

for currency in balance!.data.balance {
...
}

 

but each time this error apears:

Type ‘ApiBalanceAnswer.Detail.balance’ does not conform to protocol ‘Sequence’

 

i think its becuase it is an codable object and not an array right?

so how can i make an loop or count them?

 

many thanks for your help…

Powered by WPeMatico

About

You may also like...

Comments are closed.