We have an array with dictionaries connected via plist, we also have a CollectionView which shows all the plist dictionaries and the ViewController (VC) by which we go through the CollectionView (by cells in VC). The question is how to select the desired dictionary to change the value of one of the dictionary values ​​in the cell of which we passed.

Plist

Ps At this stage, we open the entire array and change the entire array (all dictionaries) boolean from false to True, then save and go to the specific cell to change the dictionary to which the particular cell belongs. It seems to have clearly stated his question, if not clearly write.

DetailViewController

UPD Means enumerates all dictionaries The If condition fulfills with the required index, + the value changes to true (I see in the console) remains behind the small entry in this Dictionary

This is what Console gives out (set BreackPoint in front of Write (WriteToFile))

enter image description here

    1 answer 1

    If I understand the question correctly, you need, based on the known values ​​in the dictionary, to find this very dictionary. For example, find a dictionary in the array whose value is name == Ant.

    let results:NSMutableArray = [["name":"Bug"],["name":"Ant"]] for (index, value) in results.enumerate() { let name:String = (value as! NSDictionary)["name"] as! String if(name == "Ant") { print ("found \(name) at index \(index)") var temp = value as! Dictionary<String, AnyObject> print(temp) temp["name"] = "Not Ant" results.replaceObjectAtIndex(index, withObject: temp) } } print(results) 
    • Yes, you can say so, just not by name but by index (there is a value inside the dictionary) and compare it with the dictionary that connected in this cell (by going to CollectionCell in VC, we have all the parameters of the Dictionary). Et I will try, the question is how to write True to correctText in this dictionary and will I have to write new values ​​after performing if into the entire array of Dictionaries? - Alex Gr
    • if the index is always the same - that is, array [0] will always have index == 1, then you can not check everything, but take the right one right away. write the entire array is not necessary. just replace the one you need with a new one. - Max Mikheyenko
    • It turns out I will have 20 such checks (only 20 cells (20 dictionaries) each cell has its own dictionary). What would be detrimental to smell if left so? . Updated Question Look. Brr, what do you mean? (It’s not necessary to write down the entire array. Just replace the one you need with a new one.) - Alex Gr
    • replace the correct dictionary with the corrected one. - Max Mikheyenko
    • how to describe it? if it’s not hard, try to make out mneb only with this, and I will not ask stupid questions)) - Alex Gr