[ad_1]
My app at the moment makes use of a NavigationLink to open a view like this:
LazyVGrid(columns: gridLayout, spacing: 10) {
ForEach(Array(particular person.venture! as! Set<Venture>).sorted { $0.date! > $1.date! }, id: .self) { (venture: Venture) in
NavigationLink(vacation spot: ProjectDetailView(venture: venture, rootIsActive: self.$isActive)) {
Picture(uiImage: UIImage(information: venture.image1 ?? self.projectImage1)! )
...
Nevertheless to enhance the circulate of the UI, I might like to make use of a Sheet as a substitute of NavigationLink to point out ProjectDetailView
So I modified it like this:
LazyVGrid(columns: gridLayout, spacing: 10) {
ForEach(Array(particular person.venture! as! Set<Venture>).sorted { $0.date! > $1.date! }, id: .self) { (venture: Venture) in
Picture(uiImage: UIImage(information: venture.image1 ?? self.projectImage1)! )
.onTapGesture(depend: 1) { sheet = .imageTap(venture) }
}
the place imageTap is added to my sheet enum on the prime:
enum Sheet { case imageTap(Venture) }
@State var sheet: Sheet? = nil
and my sheet modifier passes the objectID of venture to the view:
.sheet(utilizing: $sheet) { sheet in
change sheet {
case .imageTap:
ProjectDetailView(id: venture.objectID, in: viewContext)
In my ProjectDetailView I’ve outlined my @ObservedObject and initialized like this:
@Atmosphere(.managedObjectContext) non-public var viewContext
@ObservedObject var venture: Venture
init(id objectID: NSManagedObjectID, in context: NSManagedObjectContext) {
if let venture = strive? context.existingObject(with: objectID) as? Venture {
self.venture = venture
self._image1 = State(wrappedValue: venture.image1!)
self._image2 = State(wrappedValue: venture.image2 ?? self.image2)
self._image3 = State(wrappedValue: venture.image3 ?? self.image3)
self._image4 = State(wrappedValue: venture.image4 ?? self.image4)
self._fav = State(wrappedValue: venture.favourite)
} else {
self.venture = Venture(context: context)
strive? context.save()
}
}
I am anticipating the objectID to be handed into this view after I invoke the onTapGesture on the picture. Nevertheless Xcode errors at this level with
*** Terminating app as a consequence of uncaught exception 'NSInvalidArgumentException', purpose: 'nil will not be a sound object ID'
I am utilizing this similar technique of passing objectID to edit a Individual entity (my app has two core information entities: Individual and Venture), although it would not use a ForEach. It is only a .toolbar button and it really works as anticipated. So I had it print the particular person.ObjectID and it seemed like this:
0x8ae3a33c4ba2adf9 <x-coredata://468DD15D-71D2-4990-BD8B-01CAA9786420/Individual/p5>
So I went and had it print the venture.ObjectID upon tapping the picture, and it prints the same string that appears legitimate to me:
0x8ae3a33c49e2add9 <x-coredata://468DD15D-71D2-4990-BD8B-01CAA9786420/Venture/p23>
So I am fairly confused as to why ProjectDetailView is receiving a nil worth when printing the objectID upon invoking imageTap produces a sound trying objectID
Any concepts? Thanks!!
[ad_2]
