Post

Replies

Boosts

Views

Activity

Reply to allowsMultipleSelection not working via SwiftUI
There is an alternative to using UIDocumentPickerViewController so you don't have to incorporate UIKit in the picker. There's a new importFilesAction: importFiles(multipleOfType: [_Array of UTType_]) import SwiftUI struct ContentView: View { @Environment(\.importFiles) var importFiles var body: some View { Button("Show Picker") { importFiles(singleOfType: [.plainText]) { result in switch result { case .success(let url): print("Success! \(url)") case .failure(let error): print("Error: \(error.localizedDescription)") case .none: print("Cancelled") } } } } }
Jul ’20
Reply to Animation for DisclosureGroup open/close
I’ve got a way for you to be able to expand the DisclosureGroup by tapping either on the label or the arrow but not the row as a whole. DisclosureGroup(isExpanded: $guestsExpanded) { ForEach(model.guests) { ... } } label: { Button("Guests") { withAnimation { guestsExpanded.toggle() } } .foregroundColor(.primary) } I am have also encountered this strange behaviour of having to tap only on the small arrow to toggle the DisclosureGroup.
Jul ’20
Reply to Can't seem to use picker
This works for me. Not sure about the error though as it’s talking about the decimal pad keyboard type. Change your conversion variable to: var convertedValue: Double { let doubleInput = Double(self.input) ?? 0 let stringUnitFrom = self.units[self.unitFrom] if stringUnitFrom == "Farenheit" { let stringUnitTo = self.units[self.unitTo] if stringUnitTo == "Celcius" { return doubleInput * 1.8 + 32 } } return 0 } And remove @State var convertedValue: Double = 0
Jul ’20
Reply to List edit mode ios 14
You will need to add actions to each row in the list. Tapping on the edit button will do nothing to the rows. To add delete and move actions: List { ForEach(array, id: \.self) { product in Text("\(product.quantity) x \(product.name)") // delete action .onDelete { indexSet in array.remove(atOffsets: indexSet) } // move action .onMove { indexSet, newOffset in array.move(fromOffsets: indexSet, toOffset: newOffset) } } }
Aug ’20
Reply to SwiftUI EditButton problem in Xcode 12 beta
This code works for me in Xcode 12 Beta 3. struct ContentView: View { @State private var myArray: [String] = ["One", "Two", "Three"] var body: some View { NavigationView { VStack { Button("Insert item") { myArray.append("Other") } List { ForEach(myArray, id: \.self) { item in Text(item) } .onDelete { indexSet in myArray.remove(atOffsets: indexSet) } } } .navigationBarTitle("Navigation") .navigationBarItems(trailing: EditButton()) } } }
Aug ’20
Reply to Sign in with Apple in SwiftUI
This is the new easiest way with SwiftUI. SignInWithAppleButton(.signIn) { request in request.reqestedScopes = [.fullName, .email] } onCompletion: { result in switch result { case .success(let authResults): print("Authorisation successful") case .error(let error): print("Authorisation failed: \(error.localizedDescription)") } } // black button .signInWithAppleButtonStyle(.black) // white button .signInWithAppleButtonStyle(.white) // white with border .signInWithAppleButtonStyle(.whiteOutline) Or see more in the documentation - https://developer.apple.com/documentation/swiftui/signinwithapplebutton?changes=latest_minor for this.
Aug ’20
Reply to Animating Button Press
I have a solution for you. Tapping the circle expands and shrinks the border. struct ContentView: View { @State private var isPressed = false var body: some View { Circle() .fill(Color.red) .overlay(Circle() .stroke(Color.black, lineWidth: isPressed ? 10 : 2)) .onTapGesture { withAnimation { isPressed.toggle() } }     } }
Aug ’20