Thursday, 15 August 2013

Swift loop through array of dictionaries -


Why am I getting this error while looping through an array of dictionaries? Product {tableView.registerNib (for nil, forCellReuseIdentifier: identifier) ​​for UI code = import = UITableView () func meh () {product = buildCells () (identifier, nib) )}} Func buildCells () - & gt; {[String: UNINB]] {var string: uinib]] () Identifier = "identifier" give nib = uinib (nickname: "table viewule", bundle: zero) let asdf = [identifier: nib]; The meh () method causes the following error in the Collector.append (asdf) return collector}

forin in the loop:

We can not walk through the keys and values ​​of an array of dictionaries, though we can repeat through the dictionaries again and for each dictionary, we can repeat through our keys and values:Product for Dict in Product (= Identifier, Nib) Product = BuildCell () Produce {tableview.registerNib (Nib, ForCellReuseIdentifier: Identifier)}}

But I think The problem is actually more likely to be that which is going on buildCells () . Why are you returning an array of dictionaries? Do you have a duplicate key plan? I do not think Tableview will allow you to enter multiple registrations for the same identifier.

Why do not we return only one dictionary?

  func buildCells () - & gt; [String: uinib] {var dict = [string: uinib] () dick ["identifier"] = uuneb (nickname: "table viewule", bundle: zero) // rinse & amp;  

Now we can iterate over a key / value combination in the dictionary without the external keyboard:


No comments:

Post a Comment