Here is my array:
class Storages: ObservableObject {
let storage = Storage.storage()
let uid = UserAuth().uid ?? "<uid>"
@Published var photos: [String:String?] = [
"img1": UserDefaults.standard.string(forKey: "img1"),
"img2": UserDefaults.standard.string(forKey: "img2"),
"img3": UserDefaults.standard.string(forKey: "img3"),
]
And here is my view:
struct EditProfile: View {
@ObservedObject var storage = Storages()
var body: some View {
VStack {
Text("Points")
.font(Font.system(size: 21))
.fontWeight(.bold)
HStack {
ForEach(storage.photos.sorted(by: <), id: \.key){ (key,val) in
EditableCircleImage(key: key, imgName: val)
}
}
If I change by photos dictionary from [String:String?] to [String:String] (by putting in ?? "" to prevent nil value - then it will work. But I want to keep nil values as I need to know when an array item value is nil.
Here is the struct I pass into my for each:
struct EditableCircleImage: View {
@ObservedObject var storage = Storages()
let key: String
let imgName: String?
Any idea why I can't use a [String:String?]?
Command CompileSwift failed with a nonzero exit codeanderror: Segmentation fault: 11 (in target 'App' from project 'App')when I run the app - there is no compile time error, Xcode saysan internal error occured. Source editor is limited. Attempting to restore functionality...sorted(by: <). Did you overload it? If not, that is the reason.