SwiftUI add inverted mask

Here is a demo of possible approach of creating inverted mask, by SwiftUI only, (on example to make a hole in view) func HoleShapeMask(in rect: CGRect) -> Path { var shape = Rectangle().path(in: rect) shape.addPath(Circle().path(in: rect)) return shape } struct TestInvertedMask: View { let rect = CGRect(x: 0, y: 0, width: 300, height: 100) var … Read more

How to update @FetchRequest, when a related Entity changes in SwiftUI?

I also struggled with this and found a very nice and clean solution: You have to wrap the row in a separate view and use @ObservedObject in that row view on the entity. Here’s my code: WineList: struct WineList: View { @FetchRequest(entity: Wine.entity(), sortDescriptors: [ NSSortDescriptor(keyPath: \Wine.name, ascending: true) ] ) var wines: FetchedResults<Wine> var … Read more

How to Add Material to ModelEntity programatically in RealityKit?

Updated: January 26, 2023 RealityKit materials There are 6 types of materials in RealityKit 2.0 and RealityFoundation at the moment: SimpleMaterial UnlitMaterial OcclusionMaterial (read this post to find out how to setup SceneKit occlusion shader) VideoMaterial (look at this post to find out how to setup it) PhysicallyBasedMaterial CustomMaterial (Medium story) SwiftUI version Here I … Read more

SwiftUI: Error in dragging logic or is this a bug?

DragGesture‘s default CoordinateSpace is .local, which is the coordinate space inside your Circle. What happens when you move the Circle? Since your finger doesn’t move, the location of your finger in the Circle‘s geometry suddenly changes, which causes the Circle to move again. Repeat ad nauseum. Try using CoordinateSpace.global: DragGesture(minimumDistance: 10, coordinateSpace: .global) You’ll probably … Read more