Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

erdinc27

macrumors regular
Original poster
Jul 20, 2011
168
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
(

{

categoryId = 1;

categoryName = Name1;

},

{

categoryId = 2;

categoryName = Name2;

},

{

categoryId = 3;

categoryName = Name3;

},

{

categoryId = 4;

categoryName = "Name4";

},

{

categoryId = 5;

categoryName = Name5;

},

{

categoryId = 6;

categoryName = Name6;

},

{

categoryId = 7;

categoryName = Name7;

},

{

categoryId = 8;

categoryName = "Name8";

}

)

How should i iterate in such array ?
 
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)")
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.