let products = ["гречка" : "12,3,68", "рис" : "7,1,74", "овсянка" : "12,6,65"]
let userInput = "р"
for pair in products { //
if pair.key.contains(userInput) {
let elements = pair.value.components(separatedBy: ",")
print(pair.key + " contains \(elements [0])")
我需要元素[0]采取一元操作:var = 150 + element [0]
答案 0 :(得分:1)
此?
let products = ["гречка" : "12,3,68", "рис" : "7,1,74", "овсянка" : "12,6,65"]
let userInput = "р"
for pair in products { //
if pair.key.contains(userInput) {
let elements = pair.value.components(separatedBy: ",")
let number = 150 + Int(elements[0])!
print(pair.key + " contains \(number)")
}
}