0
var dic: [String: [[Item]]] //dic with string key and value of array in array of my Class Object

How can i take the values from this dic and store it in an array as this:

var array: [[Item]]//Array of array

How can I store the values from dic Into this array I tried using the for(key, value) statement. But it wouldn't let me append the values to the array variable. If you need more information I'm happy to give it, but if you understand what I'm trying to do and you know how to do it I appreciate your answer and it's very much needed!!!

0

2 Answers 2

1

If you want to get all the values in dictionary use dictionary.values, it will return you an array of all the values.

 var array = dic.values

If you want to go through each value in the dictionary use the following:

for value in dic.values {
   // println("Value: \(value)")
   array.append(value)
}
Sign up to request clarification or add additional context in comments.

1 Comment

it's not working. I thought it would but i think im having a problem bevause the value is an array of arrays at each index and I think thats where the code is having issues. Is there something I gave to do when inserting basically matric array?
0

For your first line i give you suggestion that you should create your dictionary by

var array = ["123","456","789"]
var array1 = NSMutableArray()
array1 .addObject(array)
var dict = ["String":array1]
var array3 :NSArray  = dict["String"]!
println("value ::\(array3[0])")

Output that you get is:: "value ::(\n 123,\n 456,\n 789\n)"

May this help you

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.