Post

Replies

Boosts

Views

Activity

Reply to SwiftData property marked ephemeral getting persisted in CloudKit
I think it only happens for Codable properties. In the following example, b is not persisted, but c is. struct C: Codable { var value: Int } @Model class Item { var a = 0 @Attribute(.ephemeral) var b = 0 @Attribute(.ephemeral) var c = C(value: 0) init() { } } struct ContentView: View { @Query var items: [Item] @Environment(\.modelContext) var modelContext var body: some View { List { Section { Button("add") { modelContext.insert(Item()) } } Section { ForEach(items) { item in VStack(alignment: .leading) { HStack { Text("a = \(item.a)") Button("inc") { item.a += 1 } } HStack { Text("b = \(item.b)") Button("inc") { item.b += 1 } } HStack { Text(verbatim: "c = \(item.c)") Button("inc") { item.c.value += 1 } } } .buttonStyle(.borderedProminent) } } } } } There's also a behavior that seems stranger. Whenever the app goes to background, b is reset to zero.
2w
Reply to Behavior of Image and ignoresSafeArea
I think my solid color image was a bad example because it works fine with just resizable() 😅 But a picture would be distorted without scaledToFill(). I've found another solution using an alignment value of background that is opposed to the ignored edges: .background(alignment: .bottom) { Image(.background) .resizable() .ignoresSafeArea(edges: .top) .scaledToFill() }
Topic: UI Frameworks SubTopic: SwiftUI
Jul ’25
Reply to ScrollPosition.scrollTo(id:, anchor:) not behaving as expected
I was able to achieve the same behavior by changing the anchor of scrollPosition(_:anchor:) to match scrollTo(id:anchor:) before calling: struct ContentView: View { @State private var position = ScrollPosition(edge: .top) @State private var anchor: UnitPoint? var body: some View { NavigationStack { ScrollView { VStack(spacing: 8) { ForEach(1..<100) { index in Text(verbatim: index.formatted()) .frame(maxWidth: .infinity) .background(.gray) .id(index) } } } .scrollPosition($position, anchor: anchor) .toolbar { ToolbarItemGroup(placement: .bottomBar) { Spacer() Button("50 (T)") { anchor = .top withAnimation { position.scrollTo(id: 50, anchor: .top) } } Button("50 (B)") { anchor = .bottom withAnimation { position.scrollTo(id: 50, anchor: .bottom) } } Spacer() } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
May ’25
Reply to NSPersistentCloudKitContainer's canUpdateRecord always returns true.
FWIW It's a quite simple app slightly modified from the Xcode template for CoreData + CloudKit project. struct FeedbackContentView: View { @Environment(\.managedObjectContext) private var context @FetchRequest private var items: FetchedResults<Item> var body: some View { NavigationStack { List { ForEach(items) { item in let creator = CoreDataStack.shared.container.record(for: item.objectID)?.creatorUserRecordID?.recordName VStack(alignment: .leading) { Text(item.timestamp!.formatted()) Text("Mine") .foregroundStyle(.secondary) .opacity(creator == "__defaultOwner__" ? 1 : 0) Text("Can Edit? \(CoreDataStack.shared.container.canUpdateRecord(forManagedObjectWith: item.objectID))") // Always `true` } } } } } }
Oct ’24
Reply to SwiftData property marked ephemeral getting persisted in CloudKit
I think it only happens for Codable properties. In the following example, b is not persisted, but c is. struct C: Codable { var value: Int } @Model class Item { var a = 0 @Attribute(.ephemeral) var b = 0 @Attribute(.ephemeral) var c = C(value: 0) init() { } } struct ContentView: View { @Query var items: [Item] @Environment(\.modelContext) var modelContext var body: some View { List { Section { Button("add") { modelContext.insert(Item()) } } Section { ForEach(items) { item in VStack(alignment: .leading) { HStack { Text("a = \(item.a)") Button("inc") { item.a += 1 } } HStack { Text("b = \(item.b)") Button("inc") { item.b += 1 } } HStack { Text(verbatim: "c = \(item.c)") Button("inc") { item.c.value += 1 } } } .buttonStyle(.borderedProminent) } } } } } There's also a behavior that seems stranger. Whenever the app goes to background, b is reset to zero.
Replies
Boosts
Views
Activity
2w
Reply to SwiftData property marked ephemeral getting persisted in CloudKit
I've observed this too (iOS 18.7.2 and 26.2). Looks like @Attribute(.ephemeral) does nothing and the property is annotated with @_PersistedProperty as any other property and SwiftData.Schema.Attribute(.ephemeral) metadata has no effect.
Replies
Boosts
Views
Activity
2w
Reply to Tracking multiple ImageAnchor simultaneously on VisionOS
I’m experiencing the same problem. Have you found a solution?
Replies
Boosts
Views
Activity
Aug ’25
Reply to Behavior of Image and ignoresSafeArea
I think my solid color image was a bad example because it works fine with just resizable() 😅 But a picture would be distorted without scaledToFill(). I've found another solution using an alignment value of background that is opposed to the ignored edges: .background(alignment: .bottom) { Image(.background) .resizable() .ignoresSafeArea(edges: .top) .scaledToFill() }
Topic: UI Frameworks SubTopic: SwiftUI
Replies
Boosts
Views
Activity
Jul ’25
Reply to ScrollPosition.scrollTo(id:, anchor:) not behaving as expected
I was able to achieve the same behavior by changing the anchor of scrollPosition(_:anchor:) to match scrollTo(id:anchor:) before calling: struct ContentView: View { @State private var position = ScrollPosition(edge: .top) @State private var anchor: UnitPoint? var body: some View { NavigationStack { ScrollView { VStack(spacing: 8) { ForEach(1..<100) { index in Text(verbatim: index.formatted()) .frame(maxWidth: .infinity) .background(.gray) .id(index) } } } .scrollPosition($position, anchor: anchor) .toolbar { ToolbarItemGroup(placement: .bottomBar) { Spacer() Button("50 (T)") { anchor = .top withAnimation { position.scrollTo(id: 50, anchor: .top) } } Button("50 (B)") { anchor = .bottom withAnimation { position.scrollTo(id: 50, anchor: .bottom) } } Spacer() } } } } }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to UIViewRepresentable never dismantled on deletion (MEMORY LEAK)
BTW, That's still a problem 😬
Topic: UI Frameworks SubTopic: UIKit Tags:
Replies
Boosts
Views
Activity
May ’25
Reply to NSPersistentCloudKitContainer's canUpdateRecord always returns true.
FWIW It's a quite simple app slightly modified from the Xcode template for CoreData + CloudKit project. struct FeedbackContentView: View { @Environment(\.managedObjectContext) private var context @FetchRequest private var items: FetchedResults<Item> var body: some View { NavigationStack { List { ForEach(items) { item in let creator = CoreDataStack.shared.container.record(for: item.objectID)?.creatorUserRecordID?.recordName VStack(alignment: .leading) { Text(item.timestamp!.formatted()) Text("Mine") .foregroundStyle(.secondary) .opacity(creator == "__defaultOwner__" ? 1 : 0) Text("Can Edit? \(CoreDataStack.shared.container.canUpdateRecord(forManagedObjectWith: item.objectID))") // Always `true` } } } } } }
Replies
Boosts
Views
Activity
Oct ’24