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")
}
}
}
}
}
Post
Replies
Boosts
Views
Activity
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.
This should be fixed in another beta because I’ve seen DisclosureGroups in Apple’s own apps be expandable by tapping anywhere in the row. Hopefully, this isn’t its intended behaviour in SwiftUI.
You should use two different @State properties, one for each modal view.
Because you are using the same variable for both modal views, the first one is presented.
I don’t think ScrollViewReader works with Lists yet. Hopefully, this will come in a future release.
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
This was actually fixed in Xcode 12 Beta 3.
Not that I know of yet in SwiftUI.
There are some workarounds available on the Internet though.
I would suggest suggesting this to Apple through the Feedback app if you really need this feature.
I'm getting this problem too. I guess you have to wait for the next beta.
I think in forms a single row can only have one button (or perform one button's action).
To work around this I would suggest having the checkmark button on the row below.
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)
}
}
}
SwiftUI must have everything UIKit and AppKit have, and more!
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())
}
}
}
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.
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()
}
}
}
}