Post

Replies

Boosts

Views

Activity

Trying to drag from app to finder and getting this error: Sandbox extension data required immediately for flavor public.file-url, but failed to obtain.
I'm trying to make a macOS app using SwiftUI that supports dragging arbitrary files from the app into finder. However, I'm getting this error: "Sandbox extension data required immediately for flavor public.file-url, but failed to obtain." I'm looking through the entitlements and not finding anything obvious here. I've tried various forms of NSItemProvider(): Try 1: let itemProvider = NSItemProvider(item: image.data as NSSecureCoding, typeIdentifier: image.uniformType.identifier) // Tried presenting as data itemProvider.registerDataRepresentation(for: .fileURL, visibility: .all) { completion in ... } // Tried presenting as file itemProvider.registerFileRepresentation(for: .fileURL, visibility: .all) { completion in ... } Try 2: let itemProvider1 = NSItemProvider(contentsOf: tempFileUrl, contentType: .fileURL) Tried using this form as well. In the completion handler for register*Representation(), i'm typically creating a temporary file and returning that.. (either the URL to the file or the data directly, depending on the API): let tempFileUrl = URL.temporaryDirectory.appending(path: "testfile.png") _ = tempFileUrl.startAccessingSecurityScopedResource() defer { tempFileUrl.stopAccessingSecurityScopedResource() } completion(tempFileUrl as data, nil) // option 1 completion(data, nil) // option 2 Disabling App Sandbox in the entitlements file does not work, but the error message goes away. So it seems like I have two problems: some sort of entitlement error and I must be using NSItemProvider() incorrectly. Anyone have any suggestions? I don't see to many examples out there for supporting exporting files (e.g. images) from an app into Finder. Thanks!
0
1
519
Mar ’24
AVAudioSession Float sample range
I'm using AVAudioSession to get raw samples from a microphone and trying to display a waveform. Does anyone know what is the range of values to expect? I don't see anything in the documentation. From testing, I can see that it can go up to +/- 4. The only reliable way I seem to be able to do this is to use AVAudioConverter() to convert the samples to Int16, then to normalized floats. But that seems rather inefficient.
0
0
788
Feb ’21
How to subclass XCTestCase? Or how to test protocol (or base-class) conformance without having to duplicate tests?
Hi all, I have a protocol that declares some required functions. I would like to develop a set of tests so that I can run them against 2 or more classes that conform to the protocol without having to re-write the tests for each implementation. I attempted to create an XCTestCase base class hoping to inherit from it for each class conforming to the protocol. But it does not seem like it's possible to subclass XCTestCase in Swift? For a more concrete example. Let's start with a protocol: protocol Arithmetic { 	 func add(Int, Int) -> Int 	 func multiply(Int, Int) -> Int 	/// a whole lot more } class A: Arithmetic { 		// implement add(), multiply(), etc. } class B: Arithmetic { 		// implement add(), multiply(), etc. } I would like to create an XCTestCase for A and B that can verify the behavior of methods defined. The same problem holds if Arithmetic was a base class. Perhaps I wish to test and ensure that subclass overrides still behave correctly. Currently I don't see a way around this other than to: Copy & Paste the test cases for each conforming class (or subclass) Have one "master" test that has an array of the protocol (i.e. [Arithematic]) and loop over it for every single test case. #1 is not ideal for obvious reasons. #2 is also not ideal as it makes the tests and test results more difficult to understand. In addition, it makes it difficult to re-use the tests... e.g. if the protocol is in a framework and I expect 3rd parties to be able to create conforming classes... Ideally they should also be able to test conformance without having to re-write all the tests. Any suggestions?
0
0
1.1k
Jul ’20