Post

Replies

Boosts

Views

Activity

Shared dependencies between test and production code creates library duplication
When test support code relies on production code, a diamond can occur. If this occurs across packages, it can lead to duplicated symbols and incorrect behavior at runtime despite no warnings at build time. This only occurs in Xcode and top-level application testing. This doesn't occur when the code being tested is in a separate package. I'm trying to understand how to correctly manage shared test support code which needs to access production code, or if this is the correct way and it is an Xcode bug. For a minimized example project, see https://github.com/rnapier/SupportCode. The setup includes three packages: Dependencies, which manages all the dependencies for the app and tests; Core which contains core logic and test support; and Feature, which relies on Core an contains feature-related logic and test support. Building this system causes Core.framework to show up three times in DerivedData: ./App.app/PlugIns/AppTests.xctest/Frameworks/Core_59974D35D_PackageProduct.framework ./App.app/Frameworks/Core_59974D35D_PackageProduct.framework ./PackageFrameworks/Core_59974D35D_PackageProduct.framework When unit tests are run, there is a collision on the symbol for Keychain: objc[48914]: Class _TtC8Keychain8Keychain is implemented in both /Users/ornapier/Library/Developer/Xcode/DerivedData/App-grdjljgevqofhqgflgtrqvhvbtej/Build/Products/Debug-iphonesimulator/PackageFrameworks/Core_59974D35D_PackageProduct.framework/Core_59974D35D_PackageProduct (0x100a98118) and /Users/ornapier/Library/Developer/CoreSimulator/Devices/216C441E-4AE5-45EC-8E52-FA42D8562365/data/Containers/Bundle/Application/7197F2F2-EB26-42FF-B7DB-67116159897D/App.app/PlugIns/AppTests.xctest/AppTests (0x1011002c0). One of the two will be used. Which one is undefined. This is not a benign warning. There are two distinct copies of _TtC8Keychain8Keychain and test cases will access one and the app will access a different one. This leads to mismatches when accessing static instances such as .shared. I believe this dependency graph should work, and it does work as long as the top-level testing system is a Swift module. But if it is the application, it builds successfully, but behaves incorrectly in subtle ways.
0
4
244
1w
WeatherKit in commandline app
I am trying to add WeatherKit support to a commandline app to fetch historical data. I've configured an app ID with the WeatherKit entitlement, but WeatherKit does not appear in the Capabilities list to add. When I try to access weather data, it fails with Code=4097 "connection to service named com.apple.weatherkit.authservice" suggesting it's not authorized. How do I add the WeatherKit entitlement to a commandline Swift app?
0
0
232
Dec ’24
Embedding existing lane/track in custom Instrument
I have a custom Instrument that is generally paired with Apple's HTTP Traffic instrument. Combining them in a template is inconvenient because there is no way to automatically filter to just the URLSession I want. The user must drill down into a long list of sessions and servers every time the instrument is run. The layout is also awkward because my Instrument's output is a long way from the specific HTTP track I want. Pinning these specific tracks is good, but has to be done every time and cannot be saved as a template. I would like to extract the relevant information directly into my custom instrument, so just the information I want is visible, and in an order that is useful. I can import the data from HTTPTracing and build my own tables, but is there a way to import the plot itself and reuse it? I would rather not have to re-implement Apple's fairly complex plot. If not, is there a way to access Apple's code for the HTTPTracing plots so that I can add it in my own instrument?
0
0
1k
Nov ’22
In custom Instrument, how can I include the duration in a value
I have a custom Instrument with a os-signpost-interval-schema that captures a "state" string. I would like the final plot value to be <state>: <duration>, but I don't know how to get the duration into the string. My working schema is the following, which just stores the state itself in the column: <os-signpost-interval-schema> <id>state-interval</id> <title>State Interval</title> <subsystem>"..."</subsystem> <category>"..."</category> <name>"state"</name> <start-pattern> <message>?state</message> </start-pattern> <column> <mnemonic>state</mnemonic> <title>State</title> <type>string</type> <expression>?state</expression> </column> </os-signpost-interval-schema> I would like to change the expression in the column to (str-cat ?state ": " ?duration), but that fails with: Variable '?duration' must appear in a pattern element to be used in a later expression. I don't see any way to compute this later in the graph, lane, or plot. I've also tried explicitly creating a <duration-column>, but that doesn't seem to change anything. The rest of the pieces include the table: <create-table> <id>state-table</id> <schema-ref>state-interval</schema-ref> </create-table> And the lane, which I would like to display as <state>: <duration> rather than just the duration: <lane> <title>State</title> <table-ref>state-table</table-ref> <plot> <value-from>state</value-from> </plot> </lane>
1
1
1.1k
Nov ’22
SectionFetchRequest/Result value vs reference
At 24:56 in "Bring Core Data concurrency to Swift and SwiftUI" there's the following discussion: But here's the important part. Changes to the request are committed whenever the results getter is called, so to update both the sorting and the sectioning safely... I need to update the configuration on a reference to the results that I've pulled into a local. The code in question is a property: @SectionedFetchRequest( sectionIdentifier: \.day, sortDescriptors: [SortDescriptor(\Quake.time, order: .reverse)]) private var quakes: SectionedFetchResults<String, Quake> And it is updated with: .onChange(of: selectedSort) { _ in let sortBy = sorts[selectedSort.index] let config = quakes config.sectionIdentifier = sortBy.section config.sortDescriptors = sortBy.descriptors } It's unclear what the value/reference semantics here are. quakes looks like a value type, but this is clearly treating it as a reference type. But if it's a reference type, why is the config local variable important? It feels like some kind of magic is happening here. Why is this local variable necessary, and how would I know this?
2
0
1.5k
Jun ’21