Sobes.tech
Junior — Middle

Kā var izdzēst elementu vārdnīcā?

sobes.tech AI

Atbilde no AI

iOS, lai noņemtu elementu no vārdnīcas, tiek izmantota metode removeValue(forKey:) vai var piešķirt nil vērtību atslēgai.

Piemērs:

var dict = ["key1": "value1", "key2": "value2"]
dict.removeValue(forKey: "key1") // Noņems elementu ar atslēgu "key1"

// Vai
// dict["key1"] = nil

Pēc tam elements ar norādīto atslēgu tiks izņemts no vārdnīcas.