When the content exceeds 40 lines of text, crazy behaviour starts to happen. The content jumps up and down while typing. Is there any other way to implement simple editor that can handle around 200 lines without this crazy behaviour?
Post
Replies
Boosts
Views
Activity
Xcode: 15.1
I've got (simplified) model with relationship many-to-many defined as follows
@Model
final class Item {
var title: String
@Relationship(inverse: \Tag.items) var tags: [Tag]?
init(_ title: String) {
self.title = title
}
}
@Model
final class Tag {
var name: String
var items: [Item]?
init(_ name: String) {
self.name = name
}
}
and a view with a query
struct ItemsView: View {
@Query var items: [Item]
var body: some View {
List {...}
}
init(searchText: String) {
_items = Query(filter: #Predicate<Item> { item in
if (searchText.isEmpty) {
return true
} else {
return item.tags!.contains{$0.name.localizedStandardContains(searchText)}
}
})
}
}
This code compiles but fails at runtime with an error:
Query encountered an error: SwiftData.SwiftDataError(_error: SwiftData.SwiftDataError._Error.unsupportedPredicate)
It looks like Predicate does not like optionals cause after changing tags and items to non optionals and the predicate line to
item.tags.contains{$0.name.localizedStandardContains(searchText)}
everything works perfectly fine.
So, my question is, does anybody know how to make it work with optionals?
Full code: https://github.com/m4rqs/PredicateWithOptionals.git
Let's assume that default colour system scheme is Light mode.
If I open this app and open settings window then change colour scheme to Dark and then change again to System, the main window get back the Light mode but the settings window remains in Dark mode.
If I change default colour system scheme is Dark mode, then open this app, open settings window then change colour scheme to Light and then change again to System, the main window get back the Dark mode but the settings window remains in Light mode.
What am I doing wrong? Here is simplified code to demo my issue
import SwiftUI
struct ContentView: View {
@State private var isSettingsViewPresented = false
@State private var colorScheme = ColorScheme?.none
var body: some View {
NavigationStack {
VStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundStyle(.tint)
Text("Hello, world!")
}
.toolbar {
ToolbarItem {
Button {
isSettingsViewPresented.toggle()
} label: {
Label("Settings", systemImage: "gear")
}
}
}
.sheet(isPresented: $isSettingsViewPresented) {
NavigationStack {
Form {
Picker("Colour Scheme", selection: $colorScheme) {
Text("System").tag(ColorScheme?.none)
Text("Light").tag(Optional(ColorScheme.light))
Text("Dark").tag(Optional(ColorScheme.dark))
}
}
.toolbar {
ToolbarItem(placement: .confirmationAction) {
Button("Done") {
isSettingsViewPresented.toggle()
}
}
}
}
.preferredColorScheme(colorScheme)
}
}
.preferredColorScheme(colorScheme)
}
}
I use Xcode 15.0.1, Sonoma 14.1.1
I created a simple SwiftUI app following a tutorial. When I put a breakpoint to see what value sits in a variable or any other object, I cannot see anything. Just a pointer to a memory address. Build setting is Debug with no optimisation on. See screenshots bellow.
Any suggestions?