What's new in SwiftUI

RSS for tag

Discuss the WWDC21 session What's new in SwiftUI.

Posts under wwdc21-10018 tag

50 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
751
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
763
Aug ’21
privacySensitive() doesn't work
privacySensitive() doesn't work. This is my code:     VStack {       Text("Card number")         .font(.headline)       Text("123 456 789")         .font(.headline)         .privacySensitive()     }   } Simulator Version: Version 13.0 (969) SimulatorKit 612 CoreSimulator 775 Xcode version: Version 13.0 beta 4 (13A5201i)
1
0
1.2k
Aug ’21
Why does .swipeAction set editMode?
Why does a swipe action (using the new .swipeAction in SwiftUI 5.5, currently beta 3) set editMode? Notice when you swipe that "Edit" changes to "Done"? And yet this is not like full edit mode because tapping the EditButton shows the move handles (and the ever-annoying ugly blank indentation for the absent onDelete modifier). I think my next project won't use SwiftUI. import SwiftUI struct Fruit: Identifiable {     let id: UUID = UUID()     let name: String     let color: Color } struct ListingView: View {     @State var fruits: [Fruit] = [         Fruit(name: "banana", color: .yellow),         Fruit(name: "apple", color: .green),         Fruit(name: "tomato", color: .red)]          @Environment(\.editMode) private var editMode          var body: some View {         NavigationView {             VStack(alignment: .leading) {                 List {                     ForEach(fruits) { fruit in                         NavigationLink(                             destination: ZStack {                                 fruit.color                                 Text(fruit.name).bold().font(.largeTitle)                             }                                 .navigationTitle(fruit.name),                             label: {                                 HStack(alignment: .center) {                                     fruit.color.frame(width: 30, height: 30)                                     Text(fruit.name)                                 }                             })                             .swipeActions(edge: .leading, allowsFullSwipe: false) {                                 Button(action: { delete(fruit) },                                        label: { Image(systemName: "trash") }).tint(.red)                             }                     }                     .onMove(perform: { from, to in                         fruits.move(fromOffsets: from, toOffset: to)                     })                 }             }             .navigationBarTitle("Fruits")             .toolbar {                 ToolbarItem(placement: .primaryAction) {                     EditButton()                 }             }         }     }     private func delete(_ fruit: Fruit) {         guard let index = fruits.firstIndex(where: {$0.id == fruit.id}) else { return }         fruits.remove(at: index)     } } struct ListingView_Previews: PreviewProvider {     static var previews: some View {         ListingView()     } }
1
0
2.1k
Jul ’21
Very slow performance with SwiftUI Canvas and Fish Eye Transform sample code
Hello! SwiftUI canvas looks great for my needs. I tried it out by using the Canvas with Gesture sample code in the "WWDC21 What's New in SwiftUI" session, 22 minutes in. I am running it on Xcode 13.0 Beta on M1 MacBook Air with Big Sur, on the iPad Pro 11 iOS 15 simulator I maybe get 2 or 3 frames a second, not even close to what is being shown in the video What am I missing? thx PS. It's virtually impossible to copy sample code in the MacOS WWDC Developer app
2
0
1.7k
Jul ’21
how to get coordinates from Touched point on Map using SwiftUI?
I am using SwiftUI Map. I have initially provided a specific coordination and region. However I want to create a new MapAnnotation onLongGesture. I am able to get the touchpoint where it was tapped but not able to retrieve coordinates(latitude and longitude) from those touchpoints. I know using MKMapView there is option to convert to coordinates, however I was wondering to achieve this using Map. So once user moves map and long presses, I want to retrieve coordinate from map on that position and update region to that location. Any help/suggestion would be great thanks
0
0
574
Jul ’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
751
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
763
Activity
Aug ’21
privacySensitive() doesn't work
privacySensitive() doesn't work. This is my code:     VStack {       Text("Card number")         .font(.headline)       Text("123 456 789")         .font(.headline)         .privacySensitive()     }   } Simulator Version: Version 13.0 (969) SimulatorKit 612 CoreSimulator 775 Xcode version: Version 13.0 beta 4 (13A5201i)
Replies
1
Boosts
0
Views
1.2k
Activity
Aug ’21
Reshuffling by ForEach in SwiftUI
ForEach reshuffle the array object to the last which has been changed from ObservableObject in SwiftUI.
Replies
0
Boosts
0
Views
381
Activity
Aug ’21
Why does .swipeAction set editMode?
Why does a swipe action (using the new .swipeAction in SwiftUI 5.5, currently beta 3) set editMode? Notice when you swipe that "Edit" changes to "Done"? And yet this is not like full edit mode because tapping the EditButton shows the move handles (and the ever-annoying ugly blank indentation for the absent onDelete modifier). I think my next project won't use SwiftUI. import SwiftUI struct Fruit: Identifiable {     let id: UUID = UUID()     let name: String     let color: Color } struct ListingView: View {     @State var fruits: [Fruit] = [         Fruit(name: "banana", color: .yellow),         Fruit(name: "apple", color: .green),         Fruit(name: "tomato", color: .red)]          @Environment(\.editMode) private var editMode          var body: some View {         NavigationView {             VStack(alignment: .leading) {                 List {                     ForEach(fruits) { fruit in                         NavigationLink(                             destination: ZStack {                                 fruit.color                                 Text(fruit.name).bold().font(.largeTitle)                             }                                 .navigationTitle(fruit.name),                             label: {                                 HStack(alignment: .center) {                                     fruit.color.frame(width: 30, height: 30)                                     Text(fruit.name)                                 }                             })                             .swipeActions(edge: .leading, allowsFullSwipe: false) {                                 Button(action: { delete(fruit) },                                        label: { Image(systemName: "trash") }).tint(.red)                             }                     }                     .onMove(perform: { from, to in                         fruits.move(fromOffsets: from, toOffset: to)                     })                 }             }             .navigationBarTitle("Fruits")             .toolbar {                 ToolbarItem(placement: .primaryAction) {                     EditButton()                 }             }         }     }     private func delete(_ fruit: Fruit) {         guard let index = fruits.firstIndex(where: {$0.id == fruit.id}) else { return }         fruits.remove(at: index)     } } struct ListingView_Previews: PreviewProvider {     static var previews: some View {         ListingView()     } }
Replies
1
Boosts
0
Views
2.1k
Activity
Jul ’21
How to get similar image off google
Please help, I am trying to build an iOS app. So when u take a picture u can compare it to other images online
Replies
0
Boosts
0
Views
386
Activity
Jul ’21
SwiftUI 3 - hidesBottomBarWhenPushed
The API is still not there in SwiftUI 3, is there any plan to port this UIKit API to SwiftUI or is there any recommandation how to achieve it in SwiftUI ? it should be an access modifier on NavigationLink thanks
Replies
0
Boosts
0
Views
773
Activity
Jul ’21
Very slow performance with SwiftUI Canvas and Fish Eye Transform sample code
Hello! SwiftUI canvas looks great for my needs. I tried it out by using the Canvas with Gesture sample code in the "WWDC21 What's New in SwiftUI" session, 22 minutes in. I am running it on Xcode 13.0 Beta on M1 MacBook Air with Big Sur, on the iPad Pro 11 iOS 15 simulator I maybe get 2 or 3 frames a second, not even close to what is being shown in the video What am I missing? thx PS. It's virtually impossible to copy sample code in the MacOS WWDC Developer app
Replies
2
Boosts
0
Views
1.7k
Activity
Jul ’21
how to get coordinates from Touched point on Map using SwiftUI?
I am using SwiftUI Map. I have initially provided a specific coordination and region. However I want to create a new MapAnnotation onLongGesture. I am able to get the touchpoint where it was tapped but not able to retrieve coordinates(latitude and longitude) from those touchpoints. I know using MKMapView there is option to convert to coordinates, however I was wondering to achieve this using Map. So once user moves map and long presses, I want to retrieve coordinate from map on that position and update region to that location. Any help/suggestion would be great thanks
Replies
0
Boosts
0
Views
574
Activity
Jul ’21