Search code examples
iosswiftnsarray

i cant get data from NSArray(contentsOfFile: ) and it's return nil


i have a problem i want to get data from a plist file and put it to an array variable but it doesnt work

  let path = Bundle.main.path(forResource: "SampleData", ofType: "plist")

    let dataArray = NSArray(contentsOfFile: path!)!

and this is my plist Data: enter image description here

but it doesnt work and has runtime error for NSArray return nil.


Solution

  • i found my problem . i have to set root in plist as a Array like the below pic , beacuse NSArray just can put array to a variable and it can't put a dictionary item to a variable: enter image description here