Given the following code, if line 17 isn't present there'll be a crash upon presenting the sheet.
Since content shouldn't be nil at the time of presentation, why does this crash?
import SwiftUI
struct ContentView: View {
@State private var isPresented = false
@State private var content: String?
@State private var startTask = false
var body: some View {
Text("Tap me")
.onTapGesture {
startTask = true
}
.task(id: startTask) {
guard startTask else { return }
startTask = false // <===== Crashes if removed
content = "Some message"
isPresented = true
}
.sheet(isPresented: $isPresented) {
Text(content!)
}
}
}
iOS 16.4, Xcode 14.3.1
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
My usage of TextField.focused() works fine in Xcode 14.3.1 but is broken as of Xcode 15. I first noticed it in the second beta and it's still broken as of the 4th beta.
Feedback / OpenRadar # FB12432084
import SwiftUI
struct ContentView: View {
@State private var text = ""
@FocusState var isFocused: Bool
var body: some View {
ScrollView {
TextField("Test", text: $text)
.textFieldStyle(.roundedBorder)
.focused($isFocused)
Text("Text Field Is Focused: \(isFocused.description)")
}
}
}
When passing an empty closure to a LibraryItem's snippet parameter, unexpected extra text is added to the file when the item is dragged in from the Xcode library.
Expected:
.setAction {
}
Actual:
.setAction /*@START_MENU_TOKEN@*/{
}/*@END_MENU_TOKEN@*/
Full code:
import SwiftUI
struct ContentView: View {
var body: some View {
MyView()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
struct MyView: View {
var action: (() -> Void)?
var body: some View {
Text("MyView")
.onTapGesture {
action?()
}
}
func setAction(_ action: @escaping () -> Void) -> MyView {
var copy = self
copy.action = action
return copy
}
}
struct LibraryContent: LibraryContentProvider {
func modifiers(base: MyView) -> [LibraryItem] {
[
LibraryItem(
base.setAction {
},
title: "MyView - Set action"
)
]
}
}
FB11936092
macOS 13.0.1 (22A400)
Xcode 14.1 (14B47b)
In iOS 15.5 the correct GeometryProxy.size.height value is available when a UIDevice.orientationDidChangeNotification is received. In iOS 16.0 the GeometryProxy.size.height value is outdated it (reflects the value before rotation).
Expected behavior: iPhone SE (3rd generation) (15.5) Landscape: Height is logged at 375.0. Portrait: Height is logged at 647.0.
Actual behavior: iPhone SE (3rd generation) (16.0) Landscape: Height is logged at 647.0. Portrait: Height is logged at 375.0.
Feedback FB10448199
import SwiftUI
struct ContentView: View {
let orientationDidChangeNotification =
NotificationCenter
.default
.publisher(for: UIDevice.orientationDidChangeNotification)
var body: some View {
GeometryReader { geometryProxy in
Color.clear
.onReceive(orientationDidChangeNotification) { _ in
print(geometryProxy.size.height)
}
}
}
}