[SOLVED] how to get last element (array) in dictionary [string:Any]


i have a dictionary plist and i have to get an array from that dictionary which is in the last. i have to get that array in my table

    var dict = [String: Any]()
    func readAndWriteData(){
    if let path = Bundle.main.path(forResource: "Property List", ofType: "plist") {
        var dictionary : NSDictionary?
        if var array = NSArray(contentsOfFile: path)?.firstObject as? [String:Any] {
           // array["hello"] = "hello"
            // i have get these value by using key of each values
            dictionary = NSDictionary(contentsOfFile: path)
            dict = dictionary as! [String:Any]

this is my plist


//instead of this i have taken 1 array and inside of that array i have taken dictionaries and get the values by their key

func loadPlistData() {
    let pathForFile = "UserData"
    if let path = Bundle.main.path(forResource: pathForFile, ofType: "plist") {
        // Data present
        if let items = NSArray(contentsOfFile: path) as? [[String: Any]] {
          //here i get my items

Answered By – keshav

Answer Checked By – Marilyn (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published.