Post

Replies

Boosts

Views

Activity

Reply to Searching for the position of an item in an array within an array?
It was working in the playground but not the app. As I thought I had used the code incorrectly :). With some work I got it to function in the app too. Here is how it looks now:         let button = UIButton()         button.addTarget(self, action: #selector(self.selectTack(sender:)), for: .touchUpInside)             let filteredProducts = products.filter { $0.item.contains(key)}             for product in filteredProducts {                 if let itemPosition = product.item.firstIndex(of: key) {                     let foundColor = product.colorName[itemPosition]                     if value > 0 {                     button.setTitle("\(foundColor) \(product.brand) \(product.category), amount: \(value)", for: UIControl.State.normal)                     tackStack.addArrangedSubview(button)                 }             }         }     }
Topic: Programming Languages SubTopic: Swift Tags:
Apr ’21