Post

Replies

Boosts

Views

Activity

Reply to Using Core Data with SwiftUI App Protocol
@andrewbuilder's answer is excellent. The only thing that needs to be changed is making "persistentContainer" a let instead of a lazy var. As as lazy var, the persistent container will not load in time for the first view. This caused a crash when my first view was trying to access my core data persistent container. However by making it a constant variable, this issue went away.
Jul ’20
Reply to Preview Crashes when using @FetchRequest
I've been having this issue to an I found that changing from this struct Test_Previews: PreviewProvider {     static var previews: some View {         Test()         .environment(\.managedObjectContext, CoreDataManager.shared.context)     } } to this has been the solution for me. No idea why this works, but it does. struct Test_Previews: PreviewProvider {     static var previews: some View {         let context = CoreDataManager.shared.context         return Test()         .environment(\.managedObjectContext, context)     } }
Oct ’20
Reply to PKDrawing() == PKDrawing() returns false
As thisisnotmikey said, you can check the size of the data and see if its 42 bytes, however this also doesn't work because anytime you use the eraser, it adds to the data size. So even if you have a blank canvas and only use the erase, the data size will ballon. canvasView.drawing.strokes.isEmpty seems to work well. So does canvasView == CGRect(origin: CGPoint(x: CGFloat.infinity, y: CGFloat.infinity), size: .zero).
Apr ’21
Reply to FocusState SwiftUI not working
You have to add a large delay for @FocusState to work inside of a sheet. Here is a basic example. enum FocusableField: Hashable {     case email     case password } struct ContentView: View {    @State private var show = false     var body: some View {         Button("Show"){             show.toggle()         }         .sheet(isPresented: $show){             SheetView()         }     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()             .previewLayout(.sizeThatFits)     } } struct SheetView: View{     @State private var email = ""     @State private var password = ""     @FocusState private var focus: FocusableField?               var body: some View{         NavigationView {             Form {                 TextField("email", text: $email, prompt: Text("email"))                     .focused($focus, equals: .email)                 SecureField("password", text: $password, prompt: Text("password"))                     .focused($focus, equals: .password)             }             .navigationTitle("Sign in")             .onAppear {                 DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {                     focus = .email                 }             }         }     } }
Nov ’21