Post

Replies

Boosts

Views

Activity

ImageView with systemName partly blurry
The code that has the issue is this ZStack { Image(systemName: icon.isEmpty ? "book.pages.fill" : icon) .resizable() .scaledToFit() .scaleEffect(2.5) .foregroundStyle(.ultraThickMaterial) } the book.pages.fill is completely blurry and the lung is partly blurred. If I remove the .forgroundStyle(.ultraThickMaterial) is is completely blurred. Some icons, tho, are sharp no matter the forgroundStyle is omitted or not. COULD NOT UPLOUD IMAGE Here is the complete code import SwiftUI struct FolderOverviewItemView: View { @Environment(\.colorScheme) var colorScheme @Environment(\.horizontalSizeClass) private var horizontalSizeClass @Environment(\.verticalSizeClass) private var verticalSizeClass var title: String var description: String var icon: String var image: Image? = Image("dummy") var color: Color var body: some View { Grid { GridRow() { Color.clear Color.clear Color.clear Color.clear } GridRow() { Color.clear ZStack { Image(systemName: icon.isEmpty ? "book.pages.fill" : icon) .resizable() .scaledToFit() .scaleEffect(2.5) .foregroundStyle(.ultraThickMaterial) } .gridCellColumns(2) Color.clear } GridRow() { Color.clear Color.clear Color.clear Color.clear } .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) GridRow() { HStack(alignment: .top) { VStack(alignment: .leading) { Text(title) .font(.headline) .lineLimit(1, reservesSpace: true) if horizontalSizeClass == .regular { Text(description.isEmpty ? " " : description) .font(.caption) .lineLimit(2, reservesSpace: true) .truncationMode(.tail) } else { Text(description.isEmpty ? " " : description) .font(.caption) .lineLimit(2, reservesSpace: true) .truncationMode(.middle) } } } .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .gridCellColumns(4) .padding() .background(.regularMaterial) } } .background( LinearGradient(gradient: Gradient(colors: [color.darken(by: -0.2), color.darken(by: 0.1)]), startPoint: .topLeading, endPoint: .bottomTrailing) ) } }
0
0
536
Oct ’23
Added new field to swiftdata model, now crashes
I had a simple class called Entry with one field (timestamp: Date) and I tried to add a new field without having to uninstall the app , so I would not crash. I tried implementing the MigrationPlan stuff but I do not know if I have to manually add a value to the new field or how exactly it works. Here is my code. When I use the EntrySchemaV0 it works fine but if I try to use the V1 it crashes. (could not fetch ModelContainer) I also tried it with a custom migration stage. Crashes with error (SwiftData/BackingData.swift:432: Fatal error: Expected only Arrays for Relationships - String) import Foundation import SwiftData enum EntrySchemaV0: VersionedSchema { static var versionIdentifier = Schema.Version(0, 1, 0) static var models: [any PersistentModel.Type] { [Entry.self] } @Model final class Entry { var timestamp: Date init(timestamp: Date) { self.timestamp = timestamp } } } enum EntrySchemaV1: VersionedSchema { static var versionIdentifier = Schema.Version(0, 2, 0) static var models: [any PersistentModel.Type] { [Entry.self] } @Model final class Entry { var name: String var timestamp: Date init(name: String = "", timestamp: Date = .now) { self.name = name self.timestamp = timestamp } } } enum EntryMigrationPlan: SchemaMigrationPlan { static var schemas: [any VersionedSchema.Type] { [EntrySchemaV0.self, EntrySchemaV1.self] } static var stages: [MigrationStage] { [migrateV0toV1] } static let migrateV0toV1 = MigrationStage.lightweight( fromVersion: EntrySchemaV0.self, toVersion: EntrySchemaV1.self ) }
3
3
1.4k
Oct ’23