Post

Replies

Boosts

Views

Activity

How do I get updated custom EnvironmentValues after a method call?
I have a custom EnvironmentVariable called analyticsData. On the button tap, I want to perform my button's action and then call a method to send this data. struct PrimaryButton: View { @Environment(\.analyticsData) private var analyticsData private let title: String private let action: (() -> Void) init(_ title: String, action: @escaping (() -> Void)) { self.title = title self.action = action } var body: some View { Button(action: handleTap) { Text(title) } } func handleTap() { action() // need updated value of analyticsData here! AnalyticsProxy.shared.sendAnalytics(analyticsData) } } At the point of use for this PrimaryButton, I would like to update my data dynamically. However, tapping between my 2 buttons, the data is 1 click behind. button 1 tapped, analytics output: buttonTapped = "" button 2 tapped, analytics output: buttonTapped = "B1" button 1 tapped, analytics output: buttonTapped = "B2" In my PrimaryButton handleTap method (above), I need to get the updated value of the environmentVariable before sending the analytics. Is this possible? Point of use: struct ContentView: View { @State var buttonTapped = "" var body: some View { VStack(spacing: 64) { PrimaryButton("Button 1") { buttonTapped = "B1" }.analytics(type: .event, name: "Button Tap", data: ["Button": buttonTapped]) PrimaryButton("Button 2") { buttonTapped = "B2" }.analytics(type: .event, name: "Button Tap", data: ["Button": buttonTapped]) } } }
2
0
978
Jul ’22
How to use dependencies in a Swift Package
I created a new Package with Xcode and incorporated a dependency, however when I try to use it, I get a "No such module" error. How do I use the dependency in the Package sources? In a normal project, I can easily import and use AgileDB. Here's the Package: // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(     name: "DBCore",     products: [         // Products define the executables and libraries a package produces, and make them visible to other packages.         .library(             name: "DBCore",             targets: ["DBCore"]),     ],     dependencies: [   .package(url: "https://github.com/AaronBratcher/AgileDB", from: "6.4.0")     ],     targets: [         // Targets are the basic building blocks of a package. A target can define a module or a test suite.         // Targets can depend on other targets in this package, and on products in packages this package depends on.         .target(             name: "DBCore",             dependencies: []),         .testTarget(             name: "DBCoreTests",             dependencies: ["DBCore"]),     ] ) Perhaps the AgileDB package as a dependency in the target? I tried copying that and it won't recognize it.
1
0
1.1k
Apr ’22
How do I get updated custom EnvironmentValues after a method call?
I have a custom EnvironmentVariable called analyticsData. On the button tap, I want to perform my button's action and then call a method to send this data. struct PrimaryButton: View { @Environment(\.analyticsData) private var analyticsData private let title: String private let action: (() -> Void) init(_ title: String, action: @escaping (() -> Void)) { self.title = title self.action = action } var body: some View { Button(action: handleTap) { Text(title) } } func handleTap() { action() // need updated value of analyticsData here! AnalyticsProxy.shared.sendAnalytics(analyticsData) } } At the point of use for this PrimaryButton, I would like to update my data dynamically. However, tapping between my 2 buttons, the data is 1 click behind. button 1 tapped, analytics output: buttonTapped = "" button 2 tapped, analytics output: buttonTapped = "B1" button 1 tapped, analytics output: buttonTapped = "B2" In my PrimaryButton handleTap method (above), I need to get the updated value of the environmentVariable before sending the analytics. Is this possible? Point of use: struct ContentView: View { @State var buttonTapped = "" var body: some View { VStack(spacing: 64) { PrimaryButton("Button 1") { buttonTapped = "B1" }.analytics(type: .event, name: "Button Tap", data: ["Button": buttonTapped]) PrimaryButton("Button 2") { buttonTapped = "B2" }.analytics(type: .event, name: "Button Tap", data: ["Button": buttonTapped]) } } }
Replies
2
Boosts
0
Views
978
Activity
Jul ’22
How do I show code coverage in Swift Packages?
On my M1 mac, using Xcode 13.3, I created a package and displayed the code coverage bar (Editor menu –> Code Coverage). After running tests, there is no indication of code coverage at all in the source code. How do I get code coverage when testing a package?
Replies
1
Boosts
0
Views
1.2k
Activity
Apr ’22
How to use dependencies in a Swift Package
I created a new Package with Xcode and incorporated a dependency, however when I try to use it, I get a "No such module" error. How do I use the dependency in the Package sources? In a normal project, I can easily import and use AgileDB. Here's the Package: // The swift-tools-version declares the minimum version of Swift required to build this package. import PackageDescription let package = Package(     name: "DBCore",     products: [         // Products define the executables and libraries a package produces, and make them visible to other packages.         .library(             name: "DBCore",             targets: ["DBCore"]),     ],     dependencies: [   .package(url: "https://github.com/AaronBratcher/AgileDB", from: "6.4.0")     ],     targets: [         // Targets are the basic building blocks of a package. A target can define a module or a test suite.         // Targets can depend on other targets in this package, and on products in packages this package depends on.         .target(             name: "DBCore",             dependencies: []),         .testTarget(             name: "DBCoreTests",             dependencies: ["DBCore"]),     ] ) Perhaps the AgileDB package as a dependency in the target? I tried copying that and it won't recognize it.
Replies
1
Boosts
0
Views
1.1k
Activity
Apr ’22
Associated Code?
When showing an ImageDownloader actor, the presenter said a solution on avoiding duplicate downloads is shown with the code associated with this video. When will this code be available? I don't see it on the video page.
Replies
6
Boosts
0
Views
2.9k
Activity
Jan ’22