Post

Replies

Boosts

Views

Activity

Not seeing signposts when profiling a unit test (Xcode 16.1)
While I was recently profiling some code from a Swift library, I noticed that XCTest added in signposts for the measurement tests, which I found really helpful to "home in" on the code I wanted to profile digging around in the stack trace. I tried to add my own signposts to provide just a bit of my own markers in there, but while it compiles and profiles equivalently, the signposts just aren't showing up. This is with Xcode 16.1, macOS Sequoia (15.1) and a swift library, using XCTest and profiling within one of the unit tests. Is there something in this sequence that doesn't allow the library to set up signposts and have instruments collect them? The flow I'm using: import os let subsystem = "MyLibrary" class MyClass { let logger: Logger = .init(subsystem: subsystem, category: "fastloop") let signposter: OSSignposter init() { signposter = OSSignposter(logger: logger) } func goFast() { let signpostId = signposter.makeSignpostID() let state = signposter.beginInterval("tick", id: signpostId) // ... do a bunch of work here - all synchronous signposter.endInterval("tick", state) } } Is there something I'm doing incorrectly in using this API, or not enabling to allow those signposts to be collected by the profiler? I do see the signposts that XCTests injects into the system, just not any of the ones I'm creating.
1
0
111
2d
How to wrangle Sendable ReferenceFileDocument and SwiftUI
I recently circled back to a SwiftUI Document-based app to check on warnings, etc. with Xcode 16 and Swift 6 now released. I just found a suite a new errors that indicate that ReferenceFileDocument is now expected to be Sendable, which seems very off for it fundamentally being a reference type. I followed the general pattern from earlier sample code: Building Great Apps with SwiftUI, which goes from an Observable object to adding conformance to ReferenceFileDocument in an extension. But then the various stored properties on the class cause all manner of complaint - given that they're not, in fact, sendable. What is an expected pattern that leverages a final class for the ReferenceDocument, but maintains that Sendability? Or is there a way to "opt out" of Sendability for this protocol? I'm at a bit of a loss on the expectation that ReferenceFileDocument is sendable at all, but since it's marked as such, I'm guessing there's some path - I'm just not (yet) clear on how to accomodate that.
1
0
234
Oct ’24
Loading a lighting resource for a RealityKit view on macOS - image not embedded in app bundle
I'm trying to load up a virtual skybox, different from the built-in default, for a simple macOS rendering of RealityKit content. I was following the detail at https://developer.apple.com/documentation/realitykit/environmentresource, and created a folder called "light.skybox" with a single file in it ("prairie.hdr"), and then I'm trying to load that and set it as the environment on the arView when it's created: let ar = ARView(frame: .zero) do { let resource = try EnvironmentResource.load(named: "prairie") ar.environment.lighting.resource = resource } catch { print("Unable to load resource: \(error)") } The loading always fails when I launch the sample app, reporting "Unable to load resource ..." and when I look in the App bundle, the resource that's included there as Contents/Resources/light.realityenv is an entirely different size - appearing to be the default lighting. I've tried making the folder "light.skybox" explicitly target the app bundle for inclusion, but I don't see it get embedded with it toggle that way, or just default. Is there anything I need to do to get Xcode to process and include the lighting I'm providing? (This is inspired from https://stackoverflow.com/questions/77332150/realitykit-how-to-disable-default-lighting-in-nonar-arview, which shows an example for UIKit)
4
0
521
Aug ’24
Are the new Semantic Embeddings in CoreSpotlight multi-lingual?
After watching https://developer.apple.com/wwdc24/10131, I'm curious if the semantic embeddings used to provide the "search of meaning" with this new capability are encoded with multi-lingual embeddings? In particular, if I have content that is mixed in Korean and English, can those be seamlessly indexed together and queries in one language (english) find relevant content that was offered to be indexed as Korean?
0
1
414
Jun ’24
debugging issues with Shared Private Key Bonjour connections
Like the post at https://forums.developer.apple.com/forums/thread/118035, I'm hitting an issue where I'm receiving: boringssl_session_set_peer_verification_state_from_session(448) [C1.1.1.1:2][0x12b667210] Unable to extract cached certificates from the SSL_SESSION object In my app logs. I tried to pin the SSL version to TLS 1.2 per Quinn's advice in that post, and then started digging further enabling CFNETWORK_DIAGNOSTICS=3 to see what was exposed on the Console.log (since it didn't show up in the Xcode console) The related log lines: 0 debug boringssl 15:43:04.978874-0700 MeetingNotes boringssl_context_log_message(2206) [C5:2][0x11080a760] Reading SSL3_RT_HANDSHAKE 16 bytes 0 debug boringssl 15:43:04.979007-0700 MeetingNotes boringssl_context_log_message(2206) [C5:2][0x11080a760] Writing SSL3_RT_CHANGE_CIPHER_SPEC 1 bytes 0 debug boringssl 15:43:04.979141-0700 MeetingNotes boringssl_context_log_message(2206) [C5:2][0x11080a760] Writing SSL3_RT_HANDSHAKE 16 bytes 0 debug boringssl 15:43:04.979260-0700 MeetingNotes nw_protocol_boringssl_write_bytes(87) [C5:2][0x11080a760] write request: 51 0 debug boringssl 15:43:04.979387-0700 MeetingNotes nw_protocol_boringssl_write_bytes(158) [C5:2][0x11080a760] total bytes written: 51 921460 debug boringssl 15:43:09.937961-0700 MeetingNotes boringssl_context_log_message(2206) [C5:2][0x11080a760] Writing SSL3_RT_ALERT 2 bytes 0 error boringssl 15:43:04.979630-0700 MeetingNotes boringssl_session_set_peer_verification_state_from_session(448) [C5:2][0x11080a760] Unable to extract cached certificates from the SSL_SESSION object Have a number of references to SSL3_RT in the messages, and I was curious if that indicated that I was using TLS1.3, which apparently doesn't support private shared keys. The constraints that I used riffs on the sample code from the tic-tac-toe example project: private static func tlsOptions(passcode: String) -> NWProtocolTLS.Options { let tlsOptions = NWProtocolTLS.Options() let authenticationKey = SymmetricKey(data: passcode.data(using: .utf8)!) let authenticationCode = HMAC<SHA256>.authenticationCode( for: "MeetingNotes".data(using: .utf8)!, using: authenticationKey ) let authenticationDispatchData = authenticationCode.withUnsafeBytes { DispatchData(bytes: $0) } // Private Shared Key (https://datatracker.ietf.org/doc/html/rfc4279) is *not* supported in // TLS 1.3 [https://tools.ietf.org/html/rfc8446], so this pins the TLS options to use version 1.2: // @constant tls_protocol_version_TLSv12 TLS 1.2 [https://tools.ietf.org/html/rfc5246] sec_protocol_options_set_max_tls_protocol_version(tlsOptions.securityProtocolOptions, .TLSv12) sec_protocol_options_set_min_tls_protocol_version(tlsOptions.securityProtocolOptions, .TLSv12) sec_protocol_options_add_pre_shared_key( tlsOptions.securityProtocolOptions, authenticationDispatchData as __DispatchData, stringToDispatchData("MeetingNotes")! as __DispatchData ) /* RFC 5487 - PSK with SHA-256/384 and AES GCM */ // Forcing non-standard cipher suite value to UInt16 because for // whatever reason, it can get returned as UInt32 - such as in // GitHub actions CI. let ciphersuiteValue = UInt16(TLS_PSK_WITH_AES_128_GCM_SHA256) sec_protocol_options_append_tls_ciphersuite( tlsOptions.securityProtocolOptions, tls_ciphersuite_t(rawValue: ciphersuiteValue)! ) return tlsOptions } Is there something I'm missing in setting up the proper constraints to request TLS version 1.2 with a private shared key to be used? And beyond that, any suggestions for debugging or narrowing down what might be failing?
5
0
872
Apr ’24
Is there a way to apply for formatting option to a Dataframe column outside of the explicit description(options:) method?
I'm building up a data frame for the sole purpose of using that lovely textual grid output. I'm getting output without any issue, but I'm trying to sort out how I might apply a formatter to a specific column so that print(dataframeInstance) "just works" nicely. In my use case, I'm running a function, collecting its output - appending that into a frame, and then using TabularData to get a nice output in a unit test, so I can see the patterns within the output. I found https://developer.apple.com/documentation/tabulardata/column/description(options:), but wasn't able to find any way to "pre-bind" that to a dataframe Column when I was creating it. (I have some double values that get a bit "excessive" in length due to the joys of floating point rounding) Is there a way of setting a formatter on a column at creation time, or after (using a property) that could basically use the same pattern as that description method above?
1
0
847
Nov ’23
How, or can you, define conformances for a type in a library?
I've created a library that defines an encoded reference type, and was in the process of adding Transferrable conformance to the main class that represents the data. Doing so wants a type defined for the transferrable, so I'm adding a type for this data representation into the library. The extension on UniformTypeIdentifiers is trivial, but I'd like to also mark that the type itself conforms to public.data (UTType.data). Since this is in a swift package, there isn't an application-relevant Info.plist that would normally hold these additional details. Can I add the conformance through the library? Or is the whole aspect of Transferrable and associated UTTypes expected to be something only defined at the application level?
3
0
844
Aug ’23
What is the state diagram associated with Network's NWConnection?
What are the possible transitions within NWConnection.State? Are cancelled and failed both terminal states? (Implying that I should drop the connection and attempt to set up a new one if I want to reconnect?) The common flow of setup -> preparing -> ready I've observed, but I wasn't sure how waiting fit in. What transitions are legal (and managed) by NWConnection? (mermaid couldn't handle this diagram - but I wrote it out anyway) Are these transitions all valid? [*] --> setup cancelled --> [*] failed --> [*] setup --> preparing preparing -> ready preparing -> cancelled preparing -> failed ready -> waiting ready -> failed ready -> cancelled waiting -> cancelled waiting -> preparing waiting -> failed
0
0
577
Jul ’23
Chart: How to achieve a specific X-axis (an awkward log scale)
I'm trying to determine how best to achieve a desired result within Swift Charts. I'm trying to make a sort-of "reversed" log chart. The use case here is for driving into the details of the percentiles from a series latency values stored within a histogram. The X axis percentile values I was hoping to achieve was something along the lines of: 10, 50, 90, 99, 99,9, 99.99, 99.999 With those values being fairly evenly distributed across the chart. If I look at this from an inverted sequence of: ( 1 - (some value) ).reversed() where the values are: 0.00001, 0.0001, 0.0001, 0.001, 0.01, 0.5, 0.1 But I've been struggling with how to start with those values, scale the X axis using a 1-value kind of setup, and then overlaying the values that are more human readable to achieve the end result. Any suggestions on how to tackle this scenario with customizing a chart axis?
1
0
1.6k
Mar ’23
Question about formatting of Measurement<...> items
I was experimenting in a playground with the specifying the kind of measurement with MeasurementUnit and then formatting it with the new foundation formatters, specifically MeasurementFormatter. The particular example I was using is a UnitDuration, exploring the various options and outputs. let times = [1,10,100,1000,10103,2354,83674,182549].map { Measurement<UnitDuration>(value: $0, unit: .microseconds) } print("unitStyle: .medium, unitOptions: .providedUnit") f.unitOptions = .providedUnit f.unitStyle = .medium for t in times {     print(f.string(from: t)) } What I gathered from this exploration is that the unit you use when you create a Measurement<UnitDuration> is stashed within it - in this case I created them with microseconds. What I'd like to do have a uniform scale for the times I'm printing that more aligned with the size based on the values. For example, if all my examples are recorded in microseconds, but more usefully represent milliseconds - is there a way to deal with this just in the formatting itself? I tried updating the unit representation to transform the MeasurementUnit<Duration> instances, but the unit property is a constant: Cannot assign to property: 'unit' is a 'let' constant. I did find the convert(to:) that would let me transform to another specific unit. Is there, by chance, any way to pass in the unit to use directly to a MeasurementFormatter instance, or do I need to back out and transform the various instances to get to a specific unit? Likewise, are there any built-in methods to MeasurementUnit that align the SI units chosen to the scale of the data being used as a value? Or is that something I'd need to create a heuristic/algorithm to and do and apply it myself when I wanted that result?
4
0
1.1k
Mar ’22
Has anyone had luck getting USD to compile AND work with M1/arm64 native python?
I've been trying to build and use the USD command line toolchain pieces from source on an M1/arm64 Mac - and while I've gotten it to compile, I get a crash as python attempts to load up the USD internals: ------------------------------ python terminated ------------------------------- python crashed. FATAL ERROR: Failed axiom: ' Py_IsInitialized() ' in operator() at line 148 of /Users/heckj/src/USD/pxr/base/tf/pyTracing.cpp writing crash report to [ Sparrow.local:/var/folders/8t/k6nw7pyx2qq77g8qq_g429080000gn/T//st_python.79467 ] ... done. -------------------------------------------------------------------------------- I found a number of issues at Github, which hints that this is a potentially known and ongoing problem: https://github.com/PixarAnimationStudios/USD/issues/1620 referenced issue: https://github.com/PixarAnimationStudios/USD/issues/1466 referenced issue: https://github.com/PixarAnimationStudios/USD/issues/1736 With some suggestions, but no clear resolutions. I tried the build commands that are referenced in the release details for USDPython as available on developer downloads, and fiddling it a bit got it to compile: python build_scripts/build_usd.py \ --build-args TBB,arch=arm64 \ --python --no-imaging --no-usdview \ --prefer-safety-over-speed \ --build-monolithic /opt/local/USD But I'm repeatedly hitting the crash where python isn't initializing. I've tried Python 3 from home-brew, an Anaconda version of python (intel through Rosetta), the basing it on the python included with Xcode (universal binary), and the most recent trial was with miniforge3 arm-native python that's recommended from the Metal for Tensorflow marketing page. WIth the warnings about Python disappearing from the default install, I'd like to get a mechanism in place that I'm comfortable with to get an install of USDtools, and ideally that are native to the M1 processor.
1
0
2.9k
Feb ’22
What's the pattern to provide organization around properties and methods within a struct or class?
I'm using DocC to add documentation to an existing swift package, and the basics are working great - properties and methods showing up, linked pages, all the stuff you'd hope for. I'd like to update the structure within the struct (or class) to organize the methods and properties a bit more akin to how Apple does it in their documentation - not just the default headers, but organized by why you'd use them. Can this be done in DocC using headings within the doc comments in the source file directly, or do we need to add an Extension file with the same symbol name at the top to override and provide that additional structure? The extension template looks like it might be redundant with the summary and overview sections, since that same area is (I think) what comes from the doc comments in the source headers. # ``Symbol`` Summary ## Overview Text ## Topics ### Group - ``Symbol``
1
0
1.1k
Nov ’21