swift iteration in for

Discussion in 'iOS Programming' started by erdinc27, Jul 22, 2016.

  1. erdinc27 macrumors regular

    Joined:
    Jul 20, 2011
    #1
    i have just started swift. I want to learn just basics so i try to iterate in a mutable array which has dictionaries in it. I want to reach each values and keys of that dictionaries. I wrote such a code but i cant get the current dictionary in for loop.

    Code:
    if let filePath = NSBundle.mainBundle().pathForResource("categories", ofType: "plist") {
               
                var theRawData = NSMutableArray(contentsOfFile: filePath)
           
                print("the raw data \(theRawData!)")
            }
    
    Here how the plist looks
    How should i iterate in such array ?
     
  2. Dookieman macrumors 6502

    Joined:
    Oct 12, 2009
    #2
    You can use the "for-in" loop to iterate over the array.

    e.g.

    Code:
    for i in 0..<self.array.count {
    let dictionaryObject = self.array[i]
    print("\(dictionaryObject)")
    }
     
  3. erdinc27 thread starter macrumors regular

    Joined:
    Jul 20, 2011

Share This Page