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, ...)
}
}
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
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. ?)
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:
I watched a WWDC talk on LLDB, and they showed a nice trick of calling CATransaction.flush() from the debugger, to push changes to a UIView to the screen, even when the program was paused. Is there is a similar thing we can do with Metal?
I'm using MTKView, but I can change to a lower level if that's required. The MTKView is paused, so I'm using setNeedsDisplay. As usual, I implement the draw delegate method to encode and commit a command buffer.
If I do this from LLDB:
metalView.setNeedsDisplay()
CATransaction.flush()
I can see that causes my draw function to run, but nothing shows up on screen.
Is there something else we can do to flush those metal commands to the GPU and see them on screen while stepping through the program with the debugger?
I'm working on a macOS app that I want to give "Full Disk Access". When I run from Xcode, I get "permission denied" errors when reading a file in my home directory.
What can I do so that I can run and debug from Xcode?
I dragged the binary from the derived data folder to the System Preferences list for Full Disk Access, but that seems to do nothing.
I have a UIScrollView, and its subview inside needs to respond to some touchesMoved events without scrolling. I've got it mostly working, but with one sticking point that confuses the user: if I touch and quickly move my finger, then the UIScrollView takes the gesture as a scroll, and never calls the touchesBegan, touchesMoved, etc., of its subview. However, if I touch, then pause for a bit, then drag, then things work as intended: the subview gets touchesBegan, touchesMoved, etc., and things are handled without any scrolling.
On my UIScrollView, I've set:
delaysContentTouches = false
canCancelContentTouches = true
And I've overrode touchesShouldCancel(in view: UIView). But that does not get called in the case when I quickly drag my finger.
Is there something else I need to do?
It's a simple question. I'm just trying to understand how these things fit together. Core Text doesn't seem to get updated much, but maybe that's because it's low level and doesn't need it. I assume it's still the recommended way to do low-level text things not handled by TextKit. ?
If I go to the Xcode documentation viewer and type simd_float3x3 in the search field, nothing comes up. I swear these things used to have documentation. Where is it? Is it a bug? (Xcode 13.4.1)
I've added an NSTrackingArea to my NSView because I want a certain rectangular area to show a different cursor. As expected, my view gets a call to it's cursorUpdate:(NSEvent*) method, but how do I tell whether it's an "enter" or "leave".
- (void)cursorUpdate:(NSEvent *)event {
// Do I push or pop my custom NSCursor?
}
I notice the event.modifierFlags changes from 8 to 9. But I don't see any public enum constants to test that, so I don't know if I can depend on that. The public enum contains stuff like this, in the higher bits.
typedef NS_OPTIONS(NSUInteger, NSEventModifierFlags) {
NSEventModifierFlagCapsLock = 1 << 16,
NSEventModifierFlagShift = 1 << 17,
...
The tracking area setup code:
NSRect nsRect = ...
NSTrackingAreaOptions options = NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow;
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect: nsRect options: options owner: owner userInfo: userInfo];
[myView addTrackingArea: trackingArea];
I had the following code in a program that I used to encrypt some important files. I haven't run it in a few years. It used to work, and now it seems the password is mysteriously gone from my Keychain! The return value is now errSecItemNotFound.
I'm upset with myself for not backing up the key/password somewhere else. Is there anywhere this could be hiding? Did Apple move it somewhere? I know they created this "Passwords" app in recent years, but I don't see anything in there with the "account" string I used. I run the app from Xcode, so maybe it is in the "container" data somewhere? I do see keychain files under ~/Library.
Maybe there is a way to look through old Time Machine backups. Ug. So stressful.
Just looking for pointers on where the data might be, and why it might have disappeared. Unfortunately it was not a "guessable" password, it was a generated 256 bit key, base64 encoded. Perhaps I could crack that with brute force if I'm determined enough...
public static func queryGenericPasswordAsString(account: String) throws -> String {
let query: [String: Any] = [kSecClass as String: kSecClassGenericPassword,
kSecMatchLimit as String: kSecMatchLimitOne,
kSecAttrAccount as String: account,
kSecReturnAttributes as String: true,
kSecReturnData as String: true]
var item: CFTypeRef?
let status = SecItemCopyMatching(query as CFDictionary, &item)
guard status != errSecItemNotFound else { throw KeychainError.noPassword }
...
}
Topic:
Privacy & Security
SubTopic:
General
The sample code here, has code like:
// Create a display link capable of being used with all active displays
cvReturn = CVDisplayLinkCreateWithActiveCGDisplays(&_displayLink);
But that function's doc says it's deprecated and to use NSView/NSWindow/NSScreen displayLink instead. That returns CADisplayLink, not CVDisplayLink.
Also the documentation for that displayLink method is completely empty. I'm not sure if I'm supposed to add it to run loop, or what, after I get it.
It would be nice to get an updated version of this sample project and/or have some documentation in NSView.displayLink
Topic:
Graphics & Games
SubTopic:
Metal
Does anyone use this? I can't get it working. I'm talking about code in normal swift files, not playgrounds.Example:/// 
/// 
///Neither one displays anything in the documentation popover or the Quick Help Inspector.The docs act like it works: https://developer.apple.com/library/archive/documentation/Xcode/Reference/xcode_markup_formatting_ref/Images.html#//apple_ref/doc/uid/TP40016497-CH17-SW1A lot of my code would really benefit from diagrams in documentation. I'd love to be able to use this.
I have a UI where you can navigate/push views like this: Root view > List of things > View thing > Edit thingThe "Edit thing" view can also delete it. After a delete, I want it to pop back to the "List of things". Best I've got now is to call `presentationMode.wrappedValue.dismiss()` on the "Edit thing" view, and then again in the "View thing" view, but that time inside DispatchQueue.main.async { }. It works but the double animation is kind of clunky.Is there a better way?
I'm working on a macOS SwiftUI app. I notice that Button text does not change color properly when the app changes between Dark and Light mode. Shouldn't the builtin Button be handling this automatically? The Text views seem to handle it fine and switch their text from white to black.
The Button text can become completely invisible when I go from Dark to Light mode. Restarting the app fixes it.
I can change the Dark/Light mode manually in System preferences, or it changes at certain times of day because I have it set, usually, to "Auto".
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)
)
}
}