user10109375
user10109375

Reputation: 23

How Accss JsonData from given image

array product modeldetail models

My code:

productDetailsNameLabel.text = products[indexPath.section].arr_details?[indexPath.item].productname

Getting error message:

Type Arr_Details has no subscripts member

Upvotes: 0

Views: 68

Answers (2)

Anup Kanjariya
Anup Kanjariya

Reputation: 302

arr_details not have any subscript members so you cannot access it. Please refer following example:

class Abc: NSObject {
   var arr: [Xyz] = []
   override init() {
       for i in 1...5 {
           arr.append(Xyz(number: i))
       }
   }
}

class Xyz: NSObject {
    var number: Int
    init(number: Int) {
        self.number = number
    }
}
// Use of this class
var arrAbc: [Abc] = []
for _ in 0...5 {
    arrAbc.append(Abc())
}
yourLabel.text = "\(arrAbc[0].arr[0].number)"

Upvotes: 1

James Kim
James Kim

Reputation: 49

arr_details doesn't have a subscript so that it doesn't return a value. In order to use the subscript, you have to implement it on the arr_detail type.

Upvotes: 0

Related Questions