Tom G Tom G - 22 days ago 6
iOS Question

Insert NSMutableArray data into Dictionary with one key and multiple types of values

I have my database stored in NSMutableArray and I want to insert it into Dictionary.

My database have three columns (name, detail, time) and I want it in Dictionary of type:

[String: ([String],[String],[String])]


e.g

[firstLetterOfName: ([name],[detail],[time])]


I need the Dictionary to add alphabetic sections into my TableView.

Can it be done? and how?
If I use struct how can I insert my data into the struct?

Answer

You can create a struct and then create a dictionary using it.

struct Name {
    var name: String?
    var detail: String?
    var timestamp: Double?
}

let dictionary = ["summer": Name(name: "Summer", detail: "of", timestamp: 69)]
Comments