Posts

Post not yet marked as solved
3 Replies
I checked and get the same error. The only issue I found with your code is that you declared the property with @State but you should have declared it with @Bindable. But I tried and keep getting the error. It has to be a bug. The only solution was to manage the selection from a @State property (@State private var envProfile: String?)
Post marked as solved
1 Replies
In Beta 7, all the properties need a default value or be optional. @Model public class Product { public var id:UUID = UUID() public var name: String = "" //relationship public var category:Category? public init(name: String){ self.name = name }
Post not yet marked as solved
7 Replies
Same problem. I couldn't find any solution. The macro uses PredicateExpressions enumerations to build the predicate. The enumeration includes a lot of methods but none seems to work for case insensitive searches. I hope they fix this soon or SwiftData becomes completely useless for most cases.
Post marked as solved
6 Replies
The most elegant solution I've found is to extract the view and pass the model to a @Bindable property. @Observable final class View1Model { var text: String = "" } struct View1: View { @State var viewModel = View1Model() var body: some View { View2() .environment(viewModel) } } struct View2: View { @Environment(View1Model.self) var viewModel var body: some View { View3(viewModel: viewModel) } } struct View3: View { @Bindable var viewModel: ViewModel var body: some View { TextField("Text", text: $viewModel.text) } }
Post marked as solved
1 Replies
I solved all the issues by replacing the NSSortDescriptor class by the SortDescriptor structure.
Post not yet marked as solved
22 Replies
I have the same problem in Xcode 13.2. The only solution was to uninstall the 13.2 version and install the 13.1 version again. Very annoying.
Post marked as solved
52 Replies
I have the same issue with my Mac Mini M1. It stops scrolling on browsers and it starts jumping around on other applications. I filed a bug report. I hope they fix it for the final release because it makes the Magic Trackpad useless. Here is a quick video I made to show the problem. At first, it seems to work but then stops scrolling and fails two or three more times. It keeps failing every three or four attempts or every four or five seconds. I tried everything, but nothing solves the issue. It looks like a bug in Monterrey. https://www.youtube.com/watch?v=OxhW7biM5m0
Post marked as solved
1 Replies
I got it. The option is in the Apple ID panel now. Thanks
Post marked as solved
1 Replies
I got it. It is answered in the Swift Concurrency, Behind the scenes talk. Thanks
Post marked as solved
5 Replies
Replied In Using print()
In SwiftUI, views are created inside the definition of a structure and then initialized when an instance is created from that definition, therefore, you can't execute code anywhere you want, you can only do it from inside the structure's methods or closures. For instance, if you look at your code, you tried to call the print() function in the place were the properties of the structure and its methods are defined. This is not allowed. If you want to execute code when the instance of that structure is created, you have to define the structure's initializer:import SwiftUI struct TestView : View { let myvar = 150 init() { print("myVar: \(myvar)") } var body: some View { Text("Hello World!") } }The body property is a computed property which value is defined by a closure, so you can use print() inside that closure. The problem is that closures know what value to return when they only have one statement, but if there are more than one statement, you have to specify what should be returned with the return keyword. In the following example I print a message but I specify that I want the Text view to be the value returned by the closure.import SwiftUI struct TestView : View { let myvar = 150 var body: some View { print("myVar: \(myvar)") return Text("Hello World!") } }Views like HStack or VStack are defined with a Content closure. I'm still not sure how those closures work, but they are expected to return a list of other views, so you can't call the print() function from there. If you want to print a value after a view was created, you can use the onAppear() modifier: This modifier applies to any view.import SwiftUI struct TestView : View { let myvar = 150 var body: some View { VStack { Text("Hello World!") .onAppear(perform: { print("myVar: \(self.myvar)") }) } } }I imagine there are other ways, but those are the ones I'm using right now.