Array not available: please construct an array from your lazy sequence: Array (...)

I just upgraded from swift 1.2 to 2. Im get a array 'unavailable: please create an array from your lazy sequence: Array (...) and I can't imagine how to do this to fix this

MyVariables.selectedUser = MyVariables.dictionary.keys.array[indexPath.row] as String 

What should be changed to MyVariables.dictionary.keys.array [indexPath.row] as a String?

+7
ios swift
source share
2 answers

It is said that the array property in the lazy sequence returned by keys is no longer available. In Swift 2, you use an initializer to convert a lazy sequence to an array:

 MyVariables.selectedUser = Array(MyVariables.dictionary.keys)[indexPath.row] as String 
+10
source share

In Swift1.2, values ​​in the dictionary return the LazyForwardCollection> type, for which the .array property returns Array.

In Swift2, dictionary values ​​return LazyMapCollection <[Key: Value], Value> and the .array property is abandoned because we can build an Array with an array (dict.values).

In this case you can use these lines

** let array = Array (arrayLiteral: myVariable! .keys)

var selectedUser = [indexPath.row] **

+1
source share

All Articles