I want to show a custom confirmation dialog on my iPad. It pops up looking utterly ridiculous because the size is way bigger than it needs - inches of padding on all sides.
Is there still no way to control a sheet size on iPad?
Example code:
struct ContentView: View {
@State var showSheet = false
var body: some View {
Button("Show sheet") {
showSheet = true
}.sheet(isPresented: $showSheet) {
VStack(spacing: 0) {
Text("Title")
Divider()
Text("Line 1")
Text("Line 2. Blah blah blah blah.")
Divider()
HStack {
Button("Cancel") { showSheet = false }
Divider()
Button("OK") { showSheet = false }
}.fixedSize(horizontal: false, vertical: true)
}
.frame(minWidth: 0, minHeight: 0)
.fixedSize()
}
}
}
The result:
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I think they are, but I got myself into a situation with this error:
// Inside a SwiftUI View struct...
let cancelled: @MainActor () -> Void
var body: some View {
...
Button(action: self.cancelled) { Text("Cancel") } // Error here
The compiler reports:
Converting function value of type '@MainActor () -> Void' to '() -> Void' loses global actor 'MainActor'
I originally put that attribute on the cancelled property, because in the passed-in closure, I was doing something that gave me an error about how I had to be on the MainActor.
I can't find any documentation on this.
I've tried adding png files to my project and adding them with the "+" button here, but Xcode just ignores me. No error message.
Is it looking for a specific file format? This is Xcode 13.
Here's the entire app below. On iOS 15, it pops up blank. If you dismiss it and click "Share" again, then it looks right. Is this a bug, or is the code wrong?
struct ContentView: View {
@State private var showShare = false
@State private var shareItems: [Any] = []
var body: some View {
VStack {
Text("Test ActivityViewController")
Button("Share") {
share()
}.sheet(isPresented: $showShare) {
print("dismissed")
} content: {
ActivityViewController(activityItems: shareItems)
}
}
}
func share() {
shareItems = ["test"]
showShare = true
}
}
struct ActivityViewController: UIViewControllerRepresentable {
let activityItems: [Any]
func makeUIViewController(context: Context) -> UIActivityViewController {
let c = UIActivityViewController(activityItems: activityItems, applicationActivities: nil)
return c
}
func updateUIViewController(_ uiViewController: UIActivityViewController, context: Context) {}
}
You used to be able to put two wheel Pickers side-by-side in an HStack, if you used .frame(...) to set the width, along with .clipped().
Example code from previous question here: https://developer.apple.com/forums/thread/127028
HStack(spacing: 0) {
Picker(selection: $choice1, label: Text("C1")) {
ForEach(0..<10) { n in
Text("\(n) a").tag(n)
}
}
.pickerStyle(.wheel)
.frame(minWidth: 0)
.clipped()
// repeat with second Picker
}
This is not working for me now in iOS 15. The views still appear side by side, but the touch area seems to overlap. When you try to adjust the first wheel, it spins the second one. I can move the first wheel, if I touch way over to the leading side of the screen.
(I had to add the explicit Picker style. It seems like defaulting to .menu also started in iOS 15. ?)
Simple code like this gives an error.
struct MyView: View {
@State private var test: Bool = false
var body: some View {
Text("Hello. \(test)")
The error:
Instance method 'appendInterpolation(_:formatter:)' requires that 'Bool' inherit from 'NSObject'
What is going on?
These are properties of Product. Both are type VerificationResult<Transaction>? and they seem very similar. What are some example situations where they would be different?
It would be nice if the documentation discussed this.
After updating to 12.5, I now get an error trying to run my unit tests. This is for a macOS app.
dyld: warning: could not load inserted library '/[...]/DerivedData/[...]/Contents/Frameworks/libXCTestBundleInject.dylib' into hardened process because no suitable image found. Did find:
/[...]/libXCTestBundleInject.dylib: code signature in (/[...]/libXCTestBundleInject.dylib) not valid for use in process using Library Validation: mapped file has no Team ID and is not a platform binary (signed with custom identity or adhoc?)
Anyone else face and fix this, or understand what it is?
I changed the "Signing Certificate" in my test target to "Sign to Run Locally" (from "Development") to see if that would help. It didn't fix it.
Is there a way to quickly confirm a "fix-it" popup using only the keyobard?
The "Fix Next Issue" and "Fix Previous Issue" commands just show the popup. I still have to manually press the "Fix" button. Return key simply dismisses the popup. Clicking that tiny button 1000's of times is annoying.
Xcode 12.4.
In IntelliJ I can fly through these with a nice keyboard shortcut. I'm looking for a similar thing in Xcode.
I've been using the os.Logger API, but it looks like I need to create an OSLog as well if I want to use the signpost API for tracking performance.
Is that true, or is there some way get an underlying OSLog from a Logger? Then I could write something like:
swift
extension os.Logger {
func signpost(...) {
os_signpost(.begin, ... self.osLog, ...)
}
}
I know how to add items to the main menu. But what if I want to connect a handler to one that is already there by default? (For example "Select All").
WindowGroup {
ContentView()
}.commands {
CommandGroup(after: CommandGroupPlacement.pasteboard) {
Button("Select All") { selectAll() }
}
That adds a second "Select All" menu item.
If I use CommandGroup(replacing: ...) then it replaces others, not just the "Select All"
I have a View with a DragGesture to resize something, so I tried using onHover to set the macOS cursor to the right resize icon. It doesn't work 100%, because the drag will reset the cursor. Then I have to move the pointer out of the view and back in, to re-trigger the onHover and get the resize cursor again.
swift
private struct HeaderEdgeDragArea: View {
var drag: some Gesture {
DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { value in
...
}
.onEnded { _ in
...
}
}
var body: some View {
Color.gray.zIndex(2.0).frame(width: 1.0)
.overlay(
Rectangle().frame(width: 8)
.foregroundColor(.clear)
.contentShape(Rectangle())
.border(Color.red, width: 0.5)
.onHover { hovering in
print("hovering: \(hovering)")
if hovering {
NSCursor.resizeLeftRight.push()
} else {
NSCursor.pop()
}
}
.gesture(drag)
)
}
}
I'm running this on macOS. I looks like a bug to me. If I activate the menu item and confirm the alert, the alert pops up again. It only double-shows once; then it behaves correctly. In my real app, it double-shows every time.
If I uncomment that DispatchQueue.main.async, it "fixes" it.
macOS 11.2.3, Xcode 12.4.
swift
@main
struct DoubleAlertApp: App {
@State var showAlert: Bool = false
@StateObject var model: Model = .init()
var body: some Scene {
WindowGroup {
ContentView().environmentObject(model)
.background(EmptyView()
.alert(isPresented: $showAlert) {
Alert(title: Text("Test"),
message: Text("This will do something"),
primaryButton: .cancel(),
secondaryButton: .destructive(Text("Do it"), action: confirmedAction))
})
}.commands {
CommandGroup(replacing: CommandGroupPlacement.newItem) {
Button(action: testAlert) {
Text("Test Alert")
}.keyboardShortcut("t")
}
}
}
private func testAlert() {
showAlert = true
}
private func confirmedAction() {
print("confirmedAction")
// DispatchQueue.main.async {
self.model.change()
//}
}
}
class Model: ObservableObject {
init() {}
@Published var foo: Int = 0
func change() {
objectWillChange.send()
foo += 1
}
}
struct ContentView: View {
@EnvironmentObject var model: Model
var body: some View {
Text("Hello. \(model.foo)").padding()
}
}
I have a TextField in my toolbar that I use for a search function. I want to trigger the search by hitting the "return" key in this field. But if I do it in onCommit, the search also gets triggered when the user un-focuses the field.
Is there a way to respond to just the "return" key?
TextField("Search", text: $searchQuery) { editing in
print("onEditingChanged \(editing)")
} onCommit: {
// Problem: this is triggered by both
// 1. Return key
// 2. Losing focus
searchModel.startSearch(query: searchQuery)
}
Hi,
If I change the AppIcon in Xcode's Assets.xcassets, and rerun my app, the image used in the dock and app switcher does not update. If I "Clean Build Folder", and re-run, then it updates.
This is annoying when I keep tweaking the colors in the icon and want to see how they look. A full rebuild takes a while, because I have a few Swift Package dependencies.
Anyone know a trick to get the AppIcon to stop caching (or whatever it's doing)?
I tried killall Dock and killall Finder, but that didn't help.
(macOS 11.2.3)
Rob