In this simple example, no matter what I try, I cannot get the UI to update while the lines of the stream are being read. Not until the entire stream is finished does the UI update. This happens for the built in AsyncSequence or my custom one. (I am simulating a delay, but regardless of whether or not I use it, I don't get incremental updates.)
struct ContentView: View {
@State var entries: [String] = []
var body: some View {
List {
ForEach(entries, id: \.self) { entry in
Text(entry)
}
}
.task {
do {
let (bytes, _) = try await URLSession.shared.bytes(from: URL(string: "https://itunes.apple.com/us/rss/toppodcasts/limit=1/explicit=false/genre=1301/json")!)
for try await line in bytes.lines {
await update(line)
await mySleep(1)
}
} catch {
print("Error")
}
}
}
func update(_ line: String) async {
entries.append(line)
}
func mySleep(_ seconds: Int) async {
sleep(UInt32(seconds))
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
If I query an entity with a relationship to another entity, and then I update that related entity, the view does not refresh automatically. I'm 'forcing' it now, but that doesn't seem right. What's the right way?
See code sample:
struct ContentView: View {
		@Environment(\.managedObjectContext) private var viewContext
		@FetchRequest(
				sortDescriptors: [],
				animation: .none)
		private var categories: FetchedResults<Category>
		private func forceRefresh() {
				viewContext.refresh(categories[0], mergeChanges: true)
		}
		var body: some View {
				
				VStack {
						List {
								
								ForEach(categories) { category in
										
										Section {
												Text("\(category.name!)").font(.title)
										}
										
										ForEach(category.items?.allObjects as! [Item]) { item in
												Button {
														item.name = "\(UUID())"
												} label: {
														Text("\(item.name!)").font(.caption)
												}
										}
								}
						}
						
						Divider()
						
						Button {
								forceRefresh()
						} label: {
								Text("Force Refresh").foregroundColor(.blue)
						}
				}
		}
}
I get a ton of compile errors when I compile in Release mode (i.e. Archive) my swift package that contains my CoreData .xcdatamodel file.
Works fine in debug mode, but when archiving, I get tons of “error reading dependency file…unexpected character in prerequisites at position…” errors.
Same errors as this issue: https://developer.apple.com/forums/thread/657264
If I move the .xcdatamodel to the main project (out of the package), then it's all good again, but I'd like to keep the database model file inside the package if possible.