I made a new project to figure out how List and editing List works and there was no problem at all, everything was going smoothly.
Then I transferred the code over into an existing project but I ran into an unusual problem: when I try to use custom button to change the EditMode and make List editable it does not work. However when I use the original EditButton the List goes into editing mode.
Do you have any ideas, why is this happening?
This is the code:
@Environment(\.editMode) var editMode
var body: some View {
VStack {
HStack {
Spacer()
EditButton()
.accentColor(.black)
Button(action: {
editMode?.wrappedValue = editMode?.wrappedValue == .active ? .inactive : .active
}) {
Text(editMode?.wrappedValue == .active ? "Saved" : "Modify")
}
}
.padding(.horizontal)
if emptyDictionary {
Divider()
Spacer()
Text("Nothing here yet")
.font(.light18)
Spacer()
} else {
List {
ForEach(keys, id:\.self) { color in
if !favourites(color: color).isEmpty {
Section(header: headerView(color: color)) {
ForEach(favourites(color: color)) { fav in
versRow(vers: fav, color: color)
}
.onDelete(perform: {indexSet in
store.deleteFavourites(color: color, indexSet: indexSet)
})
.onMove { (indexSet, newOffset) in
store.moveFavourites(color: color, indexSet: indexSet, newOffset: newOffset)
}
}
}
}
}
.padding(.horizontal)
}
}
}
The thing is the editMode environment variable changes with every click because the text in the custom button changes accordingly but the List does not go into editing mode. Strange.
Post
Replies
Boosts
Views
Activity
I have a list of rows of articles in a SwiftUI List. The code is the following:
struct ArticleListView: View {
var articles: [Article]
var body: some View {
List {
ForEach(articles) { a in
ArticleRow(article: a)
}
}
}
}
When I run it in the simulator it works like a charm but the Preview Canvas always returns with an error.
The Article struct conforms to Identifiable so this is not really the problem.
I have tried to play a little with the view. When I replaced the ForEach with the following:
List {
ForEach(1..<5) { i in
ArticleRow(article: articles[i])
}
}
the preview displayed the list beautifully.
But when I replaced the ForEach with the indices, like this:
List {
ForEach(articles.indices, id:\.self) { i in
ArticleRow(article: articles[i])
}
}
the Preview canvas was not able to display the view.
The error message is the same for all scenarios:
MessageSendFailure: Message send failure for update
==================================
| MessageError: Connection interrupted
Does anybody have any idea how to solve this, or is this maybe a bug in the current (13.2 and 13.2.1) Xcode version?
Thank you.
This morning I wanted to continue working on my project, but XCode suddenly showed me a lot of errors. They were absolutely silly errors, like Image doesn't have .resizable modifier e.t.c.
Then I started a new project to make sure my project is OK, and yes, XCode was full of errors even in its starting project. I attached the screenshot of the phenomenon.
What I tried so far:
Clean build folder
Quit and restart XCode
I used DevCleaner
Restart machine
Uninstall and reinstall XCode
to no avail.
Do you have any ides? Thanks.