Post

Replies

Boosts

Views

Activity

RealityKit: "annotating" an object
Hello, I want to be able to tap on a previously-placed ModelEntity box and add a dot or a text at that location on the box (kind of like I'm adding an annotation on the box) I have something like this, but not sure how I should do it correctly: class MyARView: ARView { // ... private func didTap(_ gestureRecognizer: UITapGestureRecognizer) { let pos = gestureRecognizer.location(in: self) if !didPlaceCube { placeCube(pos) return } let hitTestResult = self.hitTest(pos) guard let firstResult = hitTestResult.first else { return} let entity = firstResult.entity let textEntity = ModelEntity(mesh: .generateText("Hello there", extrusionDepth: 0.4, font: .boldSystemFont(ofSize: 0.05), containerFrame: .zero, alignment: .center, lineBreakMode: .byWordWrapping)) textEntity.setPosition(entity.position + firstResult.position, relativeTo: entity) entity.addChild(textEntity) } // ... }
0
0
760
Feb ’24
CoreData SwiftUI - List not updating
Hi, I'm creating a To-do list app with SwiftUI. There's a main 'List' view with all the lists users create. When you tap on a list, it takes you to the Detail View with the items in the list. The problem is, when I make a change to the list in the Detail View, it doesn't change in the main list. The changes are indeed getting saved, as if I restart the app, the changes are persistent. I've looked at similar issues but none of the solutions seem to be working. swift struct HomeView: View {     @Environment(\.managedObjectContext) var viewContext          @FetchRequest(entity: ItemGroup().entity, sortDescriptors: [NSSortDescriptor(keyPath: \ItemGroup.createdAt, ascending: false)])     var groups: FetchedResultsItemGroup              var body: some View {         NavigationView {             List {                 Section {                     ForEach(groups, id: \.self) { group in                         NavigationLink(destination: DetailView(group: .constant(group)), label: {                                 GroupRow(group: group)                             }) // ... swift struct GroupRow: View {     @ObservedObject var group: ItemGroup     var body: some View {         VStack(alignment: .leading) {             ProgressView(value: group.progress)             Text(group.wrappedName)             Text("\(group.ongoingItems.count) Ongoing")         }     } } swift struct DetailView: View {     @Environment(\.managedObjectContext) private var viewContext          @FetchRequest(entity: Item().entity, sortDescriptors: [NSSortDescriptor(keyPath: \Item.createdAt, ascending: false)])     private var items: FetchedResultsItem          @Binding var group: ItemGroup               var body: some View { ... Please suggest what might be the solution! Thanks!
2
0
3k
Apr ’22
RealityKit: "annotating" an object
Hello, I want to be able to tap on a previously-placed ModelEntity box and add a dot or a text at that location on the box (kind of like I'm adding an annotation on the box) I have something like this, but not sure how I should do it correctly: class MyARView: ARView { // ... private func didTap(_ gestureRecognizer: UITapGestureRecognizer) { let pos = gestureRecognizer.location(in: self) if !didPlaceCube { placeCube(pos) return } let hitTestResult = self.hitTest(pos) guard let firstResult = hitTestResult.first else { return} let entity = firstResult.entity let textEntity = ModelEntity(mesh: .generateText("Hello there", extrusionDepth: 0.4, font: .boldSystemFont(ofSize: 0.05), containerFrame: .zero, alignment: .center, lineBreakMode: .byWordWrapping)) textEntity.setPosition(entity.position + firstResult.position, relativeTo: entity) entity.addChild(textEntity) } // ... }
Replies
0
Boosts
0
Views
760
Activity
Feb ’24
CoreData SwiftUI - List not updating
Hi, I'm creating a To-do list app with SwiftUI. There's a main 'List' view with all the lists users create. When you tap on a list, it takes you to the Detail View with the items in the list. The problem is, when I make a change to the list in the Detail View, it doesn't change in the main list. The changes are indeed getting saved, as if I restart the app, the changes are persistent. I've looked at similar issues but none of the solutions seem to be working. swift struct HomeView: View {     @Environment(\.managedObjectContext) var viewContext          @FetchRequest(entity: ItemGroup().entity, sortDescriptors: [NSSortDescriptor(keyPath: \ItemGroup.createdAt, ascending: false)])     var groups: FetchedResultsItemGroup              var body: some View {         NavigationView {             List {                 Section {                     ForEach(groups, id: \.self) { group in                         NavigationLink(destination: DetailView(group: .constant(group)), label: {                                 GroupRow(group: group)                             }) // ... swift struct GroupRow: View {     @ObservedObject var group: ItemGroup     var body: some View {         VStack(alignment: .leading) {             ProgressView(value: group.progress)             Text(group.wrappedName)             Text("\(group.ongoingItems.count) Ongoing")         }     } } swift struct DetailView: View {     @Environment(\.managedObjectContext) private var viewContext          @FetchRequest(entity: Item().entity, sortDescriptors: [NSSortDescriptor(keyPath: \Item.createdAt, ascending: false)])     private var items: FetchedResultsItem          @Binding var group: ItemGroup               var body: some View { ... Please suggest what might be the solution! Thanks!
Replies
2
Boosts
0
Views
3k
Activity
Apr ’22