Post

Replies

Boosts

Views

Activity

Reply to SwiftData inside Actor leads to memory leaks
Hi, I'm using ModelActor to avoid doing query operations in the main thread, so I'm doing them in concurrent threads. However, I'm having the same problem. I'm having a memory leak that I can't figure out why. Have you been able to solve the problem? Will it cause a problem when I use it like this? I'm thinking of uploading the app to the app store, will Apple cause a problem? Thank you very much. I would be very grateful if you share your experience.
Jun ’24
Reply to @Observable conflict with @Query
If you are going to make only a simple query, I recommend you to do it in MainView. However, if you are going to apply operations to your data, it may make sense to query in the View Model. According to the research I did, before querying, you need to pass the modelContext to the View Model and then use FetchDescriptor. If you search Query in View Model on the internet, you can get more detailed information. If you have any questions, please feel free to ask. I will be happy to help you.
May ’24
Reply to I wonder swiftdata query cannot be used within a class
If you are going to make only a simple query, I recommend you to do it in MainView. If you are going to apply other operations to your data, it may make sense to use a View Model. To make a query in a View Model, you must first pass the modelContext into it. After passing it, you should use FetchDescriptor to query. You can search what you want to do on the internet by saying Query in ViewModel. I tried to explain briefly. If you have any questions, please feel free to ask. I would be very happy to help.
May ’24
Reply to Edit Swiftdata data
If I understand your problem correctly, it would be better to use @Bindable in this structure. More information about Bindable Using @Bindable @Bindable var stagione: Stagione Let's make changes in Textfields and Button TextField("Categoria", text: $stagione.categoria) Button("Aggiorna dati") { dismiss() } .disabled(!modifica) By doing this, the values in the TextFields will be saved without any function. Please feel free to ask your question :)
Apr ’24
Reply to Delay Issue with onChange Modifier in SwiftUI
Thank you sooo much for your answer. That's completely working. I did it like that for design. (I mean else section). And I would be very grateful if you could explain the code. Because it's a little confusing. Thank you again :) Picker("Marka", selection: $brandIndex) { Text("Seçin").tag(0) ForEach(cars.indices, id: \.self) { Text(cars[$0].brand).tag($0 + 1) } } .onChange(of: brandIndex) { modelIndex = 0 } if brandIndex != 0 && modelIndex <= cars[brandIndex - 1].models.count { Picker("Model", selection: $modelIndex) { Text("Seçin").tag(0) ForEach(cars[brandIndex - 1].models.indices, id: \.self) { Text(cars[brandIndex - 1].models[$0]) .tag($0 + 1) } } } else { // This section for design Picker("Model", selection: $modelIndex) { Text("Seçin").tag(0) } }
Mar ’24
Reply to Delay Issue with onChange Modifier in SwiftUI
Thank you for your answer @Claude31 . I'm trying to get the vehicle make and model from the user. I have a .json file which has all car brand and models. I'm getting values from viewModel and this is my struct: struct Car: Decodable, Identifiable { enum CodingKeys: CodingKey { case brand case models } var id = UUID() var brand: String var models: [String] } In the first picker I want to select brand. Then I want to see models according to the brand I chose. Picker("Brand", selection: $brandIndex) { Text("Choose").tag(0) ForEach(cars.indices, id: \.self) { Text(cars[$0].brand).tag($0 + 1) } } Picker("Model", selection: $modelIndex) { Text("Choose").tag(0) if brandIndex != 0 { ForEach(cars[brandIndex - 1].models.indices, id: \.self) { Text(cars[brandIndex - 1].models[$0]) .tag($0 + 1) } } } First, I select a brand and model, then when I change the brand, if the new brand does not have that value, I get the error I mentioned above. I thought that this situation would be solved if the modelIndex variable was set to 0 every time the brand was changed. Thank you so much.
Mar ’24