What's new in SwiftUI

RSS for tag

Discuss the WWDC21 session What's new in SwiftUI.

Posts under wwdc21-10018 tag

43 Posts

Post

Replies

Boosts

Views

Activity

SwiftUI3.0 What the hell is this? Help!
What the hell is this? I code a view in Xcode 13 beta 5 and run it in iOS 15 beta 6. I don't understand what these error message mean, please help! dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib import SwiftUI @available(iOS 15.0, *) struct ExerciseEditView: View {   @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>   @State var headerTitle: String = "Count"   @State var name: String = ""   @State var count: Int = 0   @State var min: Int = 0   @State var sec: Int = 0   @State var weight: Int = 0       var body: some View {     Form{       Section("Name"){         TextField("name", text: $name, prompt: Text("name"))       }                       Section(self.headerTitle){         Picker("pickTime", selection: $headerTitle){           Text("Count")             .tag("Count")           Text("Time")             .tag("Time")         }         .pickerStyle(.segmented)                   if self.headerTitle == "Time" {           Picker("time", selection: $min){             ForEach(0...60, id:\.self){value in               Text("\(value)")                 .tag(value)             }           }           .pickerStyle(.wheel)           .frame(height: 60)         }else {           Picker("count", selection: $count){             ForEach(0...100, id:\.self){value in               Text("\(value)")                 .tag(value)             }           }           .pickerStyle(.wheel)           .frame(height: 60)         }       }       Section("Weight"){         Picker("weight", selection: $weight){           ForEach(0...500, id:\.self){value in             Text("\(value)")               .tag(value)           }         }         .pickerStyle(.wheel)         .frame(height: 60)       }     }     .navigationTitle("Exercise")     .navigationBarTitleDisplayMode(.large)     .navigationBarItems(trailing: HStack{       Button(action:{         presentationMode.wrappedValue.dismiss()       }){         Text("Done")       }     })   } }
0
0
753
Aug ’21
Sidebar on the right in SwiftUI
I developing a swiftUI app for macOS. I like the side bar very much. It shows up on the left and I can add a button to open and close it. All this is good. However, I also like a similar panel on the right, so it can serve as an 'inspector' to the content I am editing. It looks like a right sidebar may not be supported in SwiftUI. So, I tried the following: NavigationView() { // Sidebar VStack(alignment: .leading) { // My sidebar views here } .frame(minWidth: 200, idealWidth: 220, maxWidth: 240) // Main Content VStack { ScrollView { LazyVGrid() { // My Grid view here } } } // Inspector View VStack(alignment: .leading) { // Inspector views here } .frame(minWidth: 200, idealWidth: 220, maxWidth: 240) } My desire was for the Inspector view will be snapped to the right and the main content to fill the center space. The above layout doesn't do that. Instead, the inspector view appears much wider and the main content shrunk. I can use the divider to resize it accoding to my need. But would love for it to appear as desired on startup. Is there any other way or workaround I can explore to achieve this?
2
0
4.1k
Aug ’21
PencilKitCanvas cannot becomeFirstResponder in SwiftUI
I have done the same thing in SwiftUI using UIViewRepresentable, but toolPicker doesn't show so I checked isFirstResponder property and I found that it was still false after I called canvas.becomeFirstResponder(). Check this out: struct NoteCanvasView: UIViewRepresentable {     func makeUIView(context: Context) -> PKCanvasView {         let canvas = PKCanvasView()         canvas.drawingPolicy = .anyInput         canvas.delegate = context.coordinator.self                  let toolPicker = PKToolPicker()         toolPicker.setVisible(true, forFirstResponder: canvas)         toolPicker.addObserver(canvas)         print(canvas.canBecomeFirstResponder)         canvas.becomeFirstResponder()         print(canvas.isFirstResponder)         return canvas     }          func updateUIView(_ canvas: PKCanvasView, context: Context) {         canvas.becomeFirstResponder()     }          func makeCoordinator() -> Coordinator {         Coordinator(self)     }          class Coordinator: NSObject {         var parent: NoteCanvasView         init(_ parent: NoteCanvasView) {             self.parent = parent         }     } } I found canvas.canBecomeFirstResponder returns true and canvas.isFirstResponder always returns false. Is this a bug in current version of SwiftUI??
0
0
792
Aug ’21
SwiftUI3.0 What the hell is this? Help!
What the hell is this? I code a view in Xcode 13 beta 5 and run it in iOS 15 beta 6. I don't understand what these error message mean, please help! dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib dyld4 config: DYLD_LIBRARY_PATH=/usr/lib/system/introspection DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib import SwiftUI @available(iOS 15.0, *) struct ExerciseEditView: View {   @Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>   @State var headerTitle: String = "Count"   @State var name: String = ""   @State var count: Int = 0   @State var min: Int = 0   @State var sec: Int = 0   @State var weight: Int = 0       var body: some View {     Form{       Section("Name"){         TextField("name", text: $name, prompt: Text("name"))       }                       Section(self.headerTitle){         Picker("pickTime", selection: $headerTitle){           Text("Count")             .tag("Count")           Text("Time")             .tag("Time")         }         .pickerStyle(.segmented)                   if self.headerTitle == "Time" {           Picker("time", selection: $min){             ForEach(0...60, id:\.self){value in               Text("\(value)")                 .tag(value)             }           }           .pickerStyle(.wheel)           .frame(height: 60)         }else {           Picker("count", selection: $count){             ForEach(0...100, id:\.self){value in               Text("\(value)")                 .tag(value)             }           }           .pickerStyle(.wheel)           .frame(height: 60)         }       }       Section("Weight"){         Picker("weight", selection: $weight){           ForEach(0...500, id:\.self){value in             Text("\(value)")               .tag(value)           }         }         .pickerStyle(.wheel)         .frame(height: 60)       }     }     .navigationTitle("Exercise")     .navigationBarTitleDisplayMode(.large)     .navigationBarItems(trailing: HStack{       Button(action:{         presentationMode.wrappedValue.dismiss()       }){         Text("Done")       }     })   } }
Replies
0
Boosts
0
Views
753
Activity
Aug ’21
Sidebar on the right in SwiftUI
I developing a swiftUI app for macOS. I like the side bar very much. It shows up on the left and I can add a button to open and close it. All this is good. However, I also like a similar panel on the right, so it can serve as an 'inspector' to the content I am editing. It looks like a right sidebar may not be supported in SwiftUI. So, I tried the following: NavigationView() { // Sidebar VStack(alignment: .leading) { // My sidebar views here } .frame(minWidth: 200, idealWidth: 220, maxWidth: 240) // Main Content VStack { ScrollView { LazyVGrid() { // My Grid view here } } } // Inspector View VStack(alignment: .leading) { // Inspector views here } .frame(minWidth: 200, idealWidth: 220, maxWidth: 240) } My desire was for the Inspector view will be snapped to the right and the main content to fill the center space. The above layout doesn't do that. Instead, the inspector view appears much wider and the main content shrunk. I can use the divider to resize it accoding to my need. But would love for it to appear as desired on startup. Is there any other way or workaround I can explore to achieve this?
Replies
2
Boosts
0
Views
4.1k
Activity
Aug ’21
PencilKitCanvas cannot becomeFirstResponder in SwiftUI
I have done the same thing in SwiftUI using UIViewRepresentable, but toolPicker doesn't show so I checked isFirstResponder property and I found that it was still false after I called canvas.becomeFirstResponder(). Check this out: struct NoteCanvasView: UIViewRepresentable {     func makeUIView(context: Context) -> PKCanvasView {         let canvas = PKCanvasView()         canvas.drawingPolicy = .anyInput         canvas.delegate = context.coordinator.self                  let toolPicker = PKToolPicker()         toolPicker.setVisible(true, forFirstResponder: canvas)         toolPicker.addObserver(canvas)         print(canvas.canBecomeFirstResponder)         canvas.becomeFirstResponder()         print(canvas.isFirstResponder)         return canvas     }          func updateUIView(_ canvas: PKCanvasView, context: Context) {         canvas.becomeFirstResponder()     }          func makeCoordinator() -> Coordinator {         Coordinator(self)     }          class Coordinator: NSObject {         var parent: NoteCanvasView         init(_ parent: NoteCanvasView) {             self.parent = parent         }     } } I found canvas.canBecomeFirstResponder returns true and canvas.isFirstResponder always returns false. Is this a bug in current version of SwiftUI??
Replies
0
Boosts
0
Views
792
Activity
Aug ’21