not getting data from dictionary array

131 Views Asked by At

this is my array

var StudentMenuData = ["house": "Home","person.crop.circle": "Profile","bell": "Notifications","message": "Messages","doc.text": "Syllabus","power": "LogOut"]

and here's i am trying to use it

for (key,value) in StudentMenuData {
  Text("")
}

but its showing this error:

Closure containing control flow statement cannot be used with result builder 'ViewBuilder'

but same code is working in playground.

1

There are 1 best solutions below

2
On BEST ANSWER

The error means what is says: Syntax like if let or fast enumeration cannot be used within the rendering area of a SwiftUI view.

A possible way is

ForEach(studentMenuData.keys.sorted(), id: \.self) { key in
   Text("\(key) -> \(studentMenuData[key]!)")
}

Side note: Please name variables with starting lowercase letter