Post

Replies

Boosts

Views

Activity

Confusing Metal family names
I'm trying to understand why my app produces weird drawings when using Metal instead of OpenGL on an old Mac Pro 2008. The system info says it belongs to macOS GPUFamily1 v3. A 2012 MacBook Pro, for which my app works fine with Metal, belongs to GPUFamily1 macOS 1. Does the first correspond to MTLFeatureSet.macOS_GPUFamily1_v3 and the second one to MTLGPUFamily.mac1 or something else? Would the second one be MTLFeatureSet.macOS_GPUFamily1_v4 or something else? The only commands I use for drawing are MTLRenderCommandEncoder.setVertexBytes(_:length:index:) , setFragmentTexture(_:index:) and drawPrimitives(type:vertexStart:vertexCount:). I think these are pretty basic commands that should work across all Metal versions, and the documentation doesn't say that they don't work on certain versions.
0
0
507
Oct ’22
UITextView with custom NSUndoManager breaks auto-enabling of software keyboard undo button
I have a custom UITextView where entering text causes the undo button in the software keyboard to be enabled. When I override the undo manager like this: class TextView: UITextView { let _undoManager = UndoManager() override var undoManager: UndoManager? { return _undoManager } } the auto-enabling of the undo button doesn't work anymore. What is the correct way of providing my own undo manager?
1
1
613
Sep ’22
Error when reading NSAttributedString from UITextPasteItem
In order to support a custom paste behaviour, In my UITextView, which I set as its own UITextPasteDelegate in awakeFromNib(), I implemented textPasteConfigurationSupporting(_:,transform:). When pressing the paste button above the software keyboard, in the callback of item.itemProvider.loadItem(forTypeIdentifier: UTType.rtf.identifier) I get an error Error Domain=NSItemProviderErrorDomain Code=-1000 "Cannot load representation of type public.rtf" UserInfo={NSLocalizedDescription=Cannot load representation of type public.rtf, NSUnderlyingError=0x28374e8e0 {Error Domain=PBErrorDomain Code=13 "Operation not authorized." UserInfo={NSLocalizedDescription=Operation not authorized.}}} even though the item.itemProvider.registeredTypeIdentifiers are "iOS rich content paste pasteboard type", "Apple Web Archive pasteboard type", "com.apple.uikit.attributedstring", "com.apple.rtfd", "com.apple.flat-rtfd", "public.utf8-plain-text", "public.rtf", "public.html", "com.apple.WebKit.custom-pasteboard-data" and item.itemProvider.canLoadObject(ofClass: NSAttributedString.self) returns true. Even item.itemProvider.loadObject(ofClass: NSAttributedString.self) returns a similar error: Error Domain=NSItemProviderErrorDomain Code=-1200 "Could not coerce an item to class NSAttributedString" UserInfo={NSLocalizedDescription=Could not coerce an item to class NSAttributedString, NSUnderlyingError=0x283497b70 {Error Domain=PBErrorDomain Code=13 "Operation not authorized." UserInfo={NSLocalizedDescription=Operation not authorized.}}}.
0
0
968
Jun ’22
Table view inside navigation controller inside popover
First: is there a way of gracefully animating the popover's size to the size of the view controller pushed onto the navigation controller, like Pages does for the three dots menu? When setting the navigation controller's preferredContentSize inside the pushed table view controller's viewWillAppear, first the push animation is run, and when it finishes, the popover is resized. Second: how to get the correct size to set as preferredContentSize? That would probably be the table view's contentSize (which, unless calling reloadData(), is .zero in viewWillAppear) plus the navigation view's title bar height. How can one calculate this, without having to sum the different parts manually?
0
0
744
May ’22
Undoing changes in Xcode doesn't remove compiler errors
It often happens that after a successful build I do some small changes that cause some compiler errors, but undoing those changes with Cmd-Z still leave the errors there. Building also doesn't remove them. Only cleaning the project and building again (which is very time consuming) or doing a small edit on the line that Xcode still thinks is wrong (such as adding a whitespace and immediately undoing it) finally gives a successful compilation again. I filed a bug report in September 2018, more than 3 years ago, and never got a response. Can it really be that I'm the only one experiencing this and why does it take so long to fix such annoying bugs and why does nobody care to give some reassurance that somebody is working on this?
0
0
360
Jan ’22
Store Swift closures and cast them back to their original type
I'm trying to create a class that can save different closures (or methods) with an argument of a specific subtype of Decodable that should be called later. This way I can predefine what actions, or methods, can be called on that class in response to some input. For example, the line addCallback(setOption(_:), SetOptionRequest.self) should result in the subsequent call to try! performCallback("setOption", JSONEncoder().encode(SetOptionRequest()) to call setOption(data) where the argument data has type SetOptionRequest. Here is the code I have so far (I took the bit about DecodableWrapper from here). The problem is that at runtime the cast callback.callback as! (ActionRequest) throws -> Void fails, since the type of the closure is not (ActionRequest) throws -> Void but (SetOptionRequest) throws -> Void. But I have no idea if and how I can cast the closure back to its original type. I considered using Selectors but I would like to keep the compile-time check that I'm binding methods with their correct argument type. struct DecodableWrapper: Decodable { static var baseType: ActionRequest.Type! var base: ActionRequest init(from decoder: Decoder) throws { self.base = try DecodableWrapper.baseType.init(from: decoder) } } open class Server { private var actionCallbacks = [String: (callback: Any, dataType: ActionRequest.Type)]() open func setup() { addCallback(setOption, action: SetOptionRequestResponse.self) } public func addCallback<T: ActionRequest>(_ callback: @escaping (_ data: T) throws -> Void, action: T.Type) { actionCallbacks[T.action] = (callback, T.self) } private func performCallback(action: String, data: Data) throws { let callback = actionCallbacks[action]! DecodableWrapper.baseType = callback.dataType let data = try! JSONDecoder().decode(DecodableWrapper.self, from: data).base try (callback.callback as! (ActionRequest) throws -> Void)(data) } private func setOption(_ data: SetOptionRequest) { } } protocol ActionRequest { static var action: String } struct Request: SetOptionRequest { }
2
0
556
Jan ’22
Xcode shows that variable is nil but it isn't
When evaluating some variables holding an optional value in the debugger with e variable, Xcode prints something like (Bool?) $R3 = nil. This gives the impression that the value is nil (what else should it mean?) and hovering that variable in the code editor also shows a popover with the content nil, but evaluating e variable?.description shows that it holds some value, for example (String?) $R4 = "false" (as a validation, the command e variable == false prints (Bool) $R6 = true. I submitted a bug report on November 2019, more than 2 years ago, and it never got any response. Is it possible that this is the expected behavior? Why can nobody fix it? I'm constantly wasting time because of this bug that causes me to make wrong assumptions during debugging.
0
1
731
Jan ’22
Creating SCNGeometryElement with SCNGeometryPrimitiveType.polygon always causes error
I'm using this code to create a rectangle (that will eventually be a more complex shape): let vertices = [simd_float3(x: 1, y: 1, z: 0), simd_float3(x: 1, y: -1, z: 0), simd_float3(x: -1, y: -1, z: 0), simd_float3(x: -1, y: 1, z: 0)] let vertexSource = SCNGeometrySource(data: Data(bytes: vertices, count: MemoryLayout<simd_float3>.size * vertices.count), semantic: .vertex, vectorCount: vertices.count, usesFloatComponents: true, componentsPerVector: 3, bytesPerComponent: MemoryLayout<Float>.size, dataOffset: 0, dataStride: MemoryLayout<simd_float3>.stride) let indices: [Int32] = Array(0..<Int32(vertices.count)) let element = SCNGeometryElement(data: Data(bytes: indices, count: MemoryLayout<Int32>.size * indices.count), primitiveType: .polygon, primitiveCount: 1, bytesPerIndex: MemoryLayout<Int32>.size) let geometry = SCNGeometry(sources: [vertexSource], elements: [element]) which logs this error in the Xcode console: [SceneKit] Error: SCNGeometryElement initialization - Invalid polygon edge count (0) There also doesn't seem to be any documentation about how to use this .polygon mode. When using .triangleStrip with a primitiveCount of 2, no error is logged.
2
0
1.7k
Jan ’22
Swipe gesture to navigate back and forth between files doesn't always work
Often performing the swipe right gesture in order to show the previously opened file doesn't work immediately. When this happens, which it does countless times a day, I have to repeat it exactly 3 times before it works. I submitted a bug report in May 2018, 3.5 years ago, and it is still marked as "Similar reports: None" and "Resolution: Open". I asked for updates a couple of times and never received a response. This makes me angry. My brain has been rewired so that when (if) this issue is finally solved I will probably continue swiping 3 times for another 2 years. At the same time, it makes me extremely sad. How can the engineers at Apple possibly leave me in the dark about if they could reproduce the issue, are working on it, or just find it unnecessary to fix it?
0
0
885
Dec ’21
Handoff with iCloud document-based app doesn't work
When tapping the Handoff icon of my app on the Mac or on the iPad, Xcode logs this error: [default personal] [ERROR] +[NSURL(BRAdditions) br_documentURLFromBookmarkableString:error:]: (passed to caller) error: Error Domain=BRCloudDocsErrorDomain Code=8 "Not Entitled" UserInfo={NSDescription=Not Entitled} When setting a breakpoint at NSApplicationDelegate.application(_:continue:restorationHandler:), I can see that userInfo.activityType is the one specified with the key NSUbiquitousDocumentUserActivityType under the Info.plist Document Types, but userActivity.userInfo is empty, so the document url is apparently not sent. Is there something else I have to set up?
1
0
1.5k
Dec ’21
I cannot delete old macOS installers, not even from the Terminal
I recently downloaded "Install macOS Catalina", "Install macOS High Sierra" and "Install macOS Mojave" and then wanted to delete them again, so I moved them to the trash, but trying to empty the trash gives the error that they are apparently being used. Even after a system restart it still happens. Trying to delete them from the Terminal via sudo rm -rf gives the error "the directory is not empty". How can I get rid of these files?
2
0
1.1k
Nov ’21