Hello guys,
this is my first post to this forum and really hope that somebody can help me here.
I would highly appreciate every help!
I am writing my first app with Swift UI (never used UIKit before) which I want to publish later on.
This is also my first app which has CoreData implemented.
For example I use the following entities:
Family, Person
1 Persons can have 1 Family
1 Family can have many Persons
My App is structured as the following:
ContentView:
Contains a TabView with 2 other views in it. A Settings View and a View with a LazyVGrid.
LazyVGrid View:
This View shows a GridItem for every Family. I get the Families with the following Fetchrequest:
@Environment(\.managedObjectContext) private var viewContext
// These are the Families from the FetchRequest
@FetchRequest(entity: Family.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \Family.created, ascending: false)]
) var families: FetchedResults<Family>
Every GridItem is linking to a "FamilyDetailView" via NavigationLink. So i pass the family as the following:
NavigationLink(destination: FamilyDetailView(family: family).environment(\.managedObjectContext, self.viewContext), label: {Text("Family Name")
In the FamilyDetailView i get the Family with a property wrapper:
@State var family : Family
In this FamilyDetailView is the problem i have.
Here I also have a LazyVGrid, which shows 1 NavigationLink for every Person in the Family in a GridItem . In this GridItem I also show for example the "name" of the Person.
When tapping the NavigationLink i get to the last View, the PersonDetailView. This View gets the Person which is also an entity which has a relationship to the Family Entity.
I pass it as the follow:
NavigationLink(
destination: PersonDetailView(person: person),
label: {Text("Person")})
In the PersonDetailView I now change the name of the person and save the changed to CoreData.
The change is saved without a problem, the problem is that when I go back, using the topleading back button from the NavigationView, the Views are not updated. I have to restart the App to see the changes..
I know that the Problem has to be with passing the Data, but I cant figuring out what I did wrong.
I really appreciate everyone trying to help me!
Thank you very very much!!
Post
Replies
Boosts
Views
Activity
Hello guys,
I have problems with this issue since weeks now, and I would be so thankful for someone to help me out!
I have 2 Core Data Entitys:
Bill
Items
1 Bill can have many Items
Now in my View I get passed a bill entity and want to access its items, but I cant do so.
When debuging, bill.items?.count always is 0 and looping over bill.items also doesnt work.
Can someone please tell me how to do it?
Appreciate it so much!!
Hello guys!
I have the following problem:
In my Main SwiftUI file (the one who calls the ContentView). I have 5 StateObjects which are all passed to the environment.
3 of them are DataModels which i always want to have access to, 1 is a Sheet Manager who have the information which sheet has to be shown or not and the other one is a Manager Class which has to collect the informations in the App to create a PDF from it afterwards.
import Firebase
@main
struct BillApp: App {
@StateObject var billModel = BillModel()
@StateObject var customerModel = CustomerModel()
@StateObject var itemModel = ItemModel()
@StateObject var sheet = Sheet()
@StateObject var manager : PDFManager = PDFManager()
init() {
FirebaseApp.configure()
}
var body: some Scene {
WindowGroup {
MainView()
.environmentObject(billModel)
.environmentObject(customerModel)
.environmentObject(itemModel)
.environmentObject(sheet)
.environmentObject(manager)
.onAppear(perform: {
billModel.getData()
customerModel.getData()
itemModel.getData()
})
}
}
}
My problem is, that in my PDFManager i need the billModel which was put in the environment at the same time, because this model has the function to save the bill to the Firebase DB.
class PDFManager: ObservableObject {
@EnvironmentObject var billModel : BillModel
func saveToDB() {
billModel.addData(billToAdd: bill)
}
When I try to call the functions from the billModel I get the following error:
Thread 1: Fatal error: No ObservableObject of type BillModel found. A View.environmentObject(_:) for BillModel may be missing as an ancestor of this view.
Do you guys have any ideas how i could fix this and have the PDFManager still created on the same place and have it in the environment? I have to access it in a lot of files.
I would appreciate your help so much, thank in advance!!
Hello guys,
I am trying to get ObjectCapturing up and running. Ob the physical device side everything works great (except sind the Framework update which needed code adjustments and still crashes while reconstructing).
I marked every class with @available(iOS 17.0, *) and the projects also runs on devices with iOS 16.
The problem is, that when i want to build the project on the simulator (i know it wont work there but the scan is part of a bigger App and I need to keep simulator functionality for testing other features), the build fails because he cant find the ObjectCaptureSession.
Is there any known way to fix this?
Thanks in advance!
Kind Regards