Post

Replies

Boosts

Views

Activity

How to create bar chart with two or more bars per time period
Environment: Xcode 14.1 beta 3 on macOS Ventura Beta 9. No longer need this, I found example of this. struct LocationsChart: View {     var body: some View {         Chart {             ForEach(seriesData, id: \.city) { series in                 ForEach(series.data, id: \.weekday) {                     BarMark(                         x: .value("Weekday", $0.weekday, unit: .day),                         y: .value("Sales", $0.sales)                     )                 }                 .foregroundStyle(by: .value("City", series.city))                 .position(by: .value("City", series.city))             }         }     }     let seriesData = [         (             city: "Cupertino", data: [                 (weekday: date(year: 2022, month: 5, day: 2), sales: 54),                 (weekday: date(year: 2022, month: 5, day: 3), sales: 42),                 (weekday: date(year: 2022, month: 5, day: 4), sales: 88),                 (weekday: date(year: 2022, month: 5, day: 5), sales: 49),                 (weekday: date(year: 2022, month: 5, day: 6), sales: 42),                 (weekday: date(year: 2022, month: 5, day: 7), sales: 125),                 (weekday: date(year: 2022, month: 5, day: 8), sales: 67)             ]         ),         (             city: "San Francisco", data: [                 (weekday: date(year: 2022, month: 5, day: 2), sales: 81),                 (weekday: date(year: 2022, month: 5, day: 3), sales: 90),                 (weekday: date(year: 2022, month: 5, day: 4), sales: 52),                 (weekday: date(year: 2022, month: 5, day: 5), sales: 72),                 (weekday: date(year: 2022, month: 5, day: 6), sales: 84),                 (weekday: date(year: 2022, month: 5, day: 7), sales: 84),                 (weekday: date(year: 2022, month: 5, day: 8), sales: 137)             ]         )     ] } func date(year: Int, month: Int, day: Int = 1) -> Date {     Calendar.current.date(from: DateComponents(year: year, month: month, day: day)) ?? Date() }
0
0
1.1k
Oct ’22
macOS Xcode 14.2 app applicationwillterminate function is not called
I want to put some code to be run when my app terminates but the following:        func applicationWillTerminate(_ aNotification: Notification) {             // Insert code here to tear down your application             print("Termination Code")         } in the AppDelegate class is not called, any ideas how to fix this issue. I saw this posts https://developer.apple.com/forums/thread/126418 but I do not have an info.plist. I think the info.plist is not longer needed. The following doc does not have much to say about this?? https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428522-applicationwillterminate
4
0
1.5k
Jan ’23
Progress Indicator not working as expected
I have a test project with a bar progress indicator create on Ventura with Xcode 14.3.1., It does not show the any animation until the @IBAction function completes. I want to show progress as it progresses not a just the end? Any ideas how to fix this? Below is my test project code.. // // ViewController.swift // ProgressTest // // Created by Bob on 6/5/23. // import Cocoa class ViewController: NSViewController { @IBOutlet weak var progressIndicator: NSProgressIndicator! // var progress: Double = 0.0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } @IBAction func progressStart(_ sender: Any) { // Start the progress animation progressIndicator.startAnimation(self) // Do some work here... // Do some work here... var progress: Double = 0.0 for _ in 0..<100 { // Update the progress value in a loop progress += 1.0 progressIndicator.doubleValue = progress // progress = Double(i) // progressIndicator.increment(by: 10) // progressIndicator.doubleValue = progress // Do some work here... } // Stop the progress animation progressIndicator.stopAnimation(self) } } thanks Bob
3
0
1.4k
Jun ’23
How to customize buttons in a SwiftUI view toolbar
I have the following test code import SwiftUI struct ContentView: View { @State private var field1 = "" @State private var field2 = "" @State private var field3 = "" var body: some View { VStack { Form { Section(header: Text("Input Fields")) { TextField("Field 1", text: $field1) TextField("Field 2", text: $field2) TextField("Field 3", text: $field3) } } List { ForEach(1..<6) { index in Text("Item \(index)") } } .listStyle(InsetListStyle()) } .navigationTitle("Form and List View") .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Dismiss") { // Handle dismiss action } .foregroundStyle(.red) // } ToolbarItem(placement: .primaryAction) { Button("Done") { // Handle done action } .foregroundStyle(.green) // } } } } I can't customize the color of the Buttons. Besides .foreground modifier I have tried ..foregroundColor(.red) and .foregroundColor(.green) to no avail. How can I customize the buttons in the toolbar for both macOS and IOS
3
0
1.1k
Aug ’23
SwiftChart with secondary Y Axis
I created a SwiftChart as below and I would like to have two YAxis, one for amount and the second for count. So, the amount YAxis is a different scale then the count YAxis. Does anybody have an example of this or shed some light on coding two different YAxis? Thanks ForEach(seriesArt) { series in ForEach(series.chartSeries.chartEntry) { BarMark( x: .value("Tier", $0.tier), y: .value("Price", $0.keyValue) ) } .foregroundStyle(by: .value("Count", series.chartCategory)) .position(by: .value("Price", series.chartCategory)) } } .frame(width: 400, height: 200) .chartXAxis { AxisMarks(position: .bottom, values: .automatic) { AxisValueLabel() .foregroundStyle(Color.white) } } .chartYAxis { AxisMarks(position: .leading, values: .automatic) { value in AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1)) AxisValueLabel() { if let intValue = value.as(Int.self) { Text("\(intValue)") .font(.system(size: 10)) .foregroundColor(.white) } } } .chartYAixs - for count sum by tier which needs to be a different scale from the amount YAxis } } }
1
0
1.1k
Apr ’24
How to see current window?
Is there a way with code I can in a general routine, which gets activated with CMD+P that shows the name of the window that was previously in focus? If so, how is this done?
Topic: UI Frameworks SubTopic: AppKit Tags:
Replies
1
Boosts
0
Views
502
Activity
Aug ’22
Customize NSTableView alternate rows color
I would like customize the nstableview alternate row color as light blue instead og light gray. How is this done? thanks
Replies
0
Boosts
0
Views
610
Activity
Aug ’22
How to create bar chart with two or more bars per time period
Environment: Xcode 14.1 beta 3 on macOS Ventura Beta 9. No longer need this, I found example of this. struct LocationsChart: View {     var body: some View {         Chart {             ForEach(seriesData, id: \.city) { series in                 ForEach(series.data, id: \.weekday) {                     BarMark(                         x: .value("Weekday", $0.weekday, unit: .day),                         y: .value("Sales", $0.sales)                     )                 }                 .foregroundStyle(by: .value("City", series.city))                 .position(by: .value("City", series.city))             }         }     }     let seriesData = [         (             city: "Cupertino", data: [                 (weekday: date(year: 2022, month: 5, day: 2), sales: 54),                 (weekday: date(year: 2022, month: 5, day: 3), sales: 42),                 (weekday: date(year: 2022, month: 5, day: 4), sales: 88),                 (weekday: date(year: 2022, month: 5, day: 5), sales: 49),                 (weekday: date(year: 2022, month: 5, day: 6), sales: 42),                 (weekday: date(year: 2022, month: 5, day: 7), sales: 125),                 (weekday: date(year: 2022, month: 5, day: 8), sales: 67)             ]         ),         (             city: "San Francisco", data: [                 (weekday: date(year: 2022, month: 5, day: 2), sales: 81),                 (weekday: date(year: 2022, month: 5, day: 3), sales: 90),                 (weekday: date(year: 2022, month: 5, day: 4), sales: 52),                 (weekday: date(year: 2022, month: 5, day: 5), sales: 72),                 (weekday: date(year: 2022, month: 5, day: 6), sales: 84),                 (weekday: date(year: 2022, month: 5, day: 7), sales: 84),                 (weekday: date(year: 2022, month: 5, day: 8), sales: 137)             ]         )     ] } func date(year: Int, month: Int, day: Int = 1) -> Date {     Calendar.current.date(from: DateComponents(year: year, month: month, day: day)) ?? Date() }
Replies
0
Boosts
0
Views
1.1k
Activity
Oct ’22
Is it possible to have secondary y axis with different scale?
Environment : macOS Ventura Xcode beta 14.1: I have the following chart I was using to learn about SwifUI Charts: I wanted to have different scales on the leading and trailing yaxis as well as have the first 3 bars to use leading scale and the last two bars use the trailing scale. Can this be done? If so, how? Thanks
Replies
1
Boosts
0
Views
1.2k
Activity
Oct ’22
How to change the text color for SwiftUI Chart's legend text?
For a macOS app using Xcode 14.1. I have a bar chart with two bars for each interval. See screen chart below. I want to change the "Invoice" and Payments" text I can't seem to find a modifier for the Legend text. How do you change the text color for SwiftUI Chart's legend text?
Replies
3
Boosts
0
Views
3.4k
Activity
Nov ’22
macOS Xcode 14.2 app applicationwillterminate function is not called
I want to put some code to be run when my app terminates but the following:        func applicationWillTerminate(_ aNotification: Notification) {             // Insert code here to tear down your application             print("Termination Code")         } in the AppDelegate class is not called, any ideas how to fix this issue. I saw this posts https://developer.apple.com/forums/thread/126418 but I do not have an info.plist. I think the info.plist is not longer needed. The following doc does not have much to say about this?? https://developer.apple.com/documentation/appkit/nsapplicationdelegate/1428522-applicationwillterminate
Replies
4
Boosts
0
Views
1.5k
Activity
Jan ’23
Progress Indicator not working as expected
I have a test project with a bar progress indicator create on Ventura with Xcode 14.3.1., It does not show the any animation until the @IBAction function completes. I want to show progress as it progresses not a just the end? Any ideas how to fix this? Below is my test project code.. // // ViewController.swift // ProgressTest // // Created by Bob on 6/5/23. // import Cocoa class ViewController: NSViewController { @IBOutlet weak var progressIndicator: NSProgressIndicator! // var progress: Double = 0.0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override var representedObject: Any? { didSet { // Update the view, if already loaded. } } @IBAction func progressStart(_ sender: Any) { // Start the progress animation progressIndicator.startAnimation(self) // Do some work here... // Do some work here... var progress: Double = 0.0 for _ in 0..<100 { // Update the progress value in a loop progress += 1.0 progressIndicator.doubleValue = progress // progress = Double(i) // progressIndicator.increment(by: 10) // progressIndicator.doubleValue = progress // Do some work here... } // Stop the progress animation progressIndicator.stopAnimation(self) } } thanks Bob
Replies
3
Boosts
0
Views
1.4k
Activity
Jun ’23
How to customize buttons in a SwiftUI view toolbar
I have the following test code import SwiftUI struct ContentView: View { @State private var field1 = "" @State private var field2 = "" @State private var field3 = "" var body: some View { VStack { Form { Section(header: Text("Input Fields")) { TextField("Field 1", text: $field1) TextField("Field 2", text: $field2) TextField("Field 3", text: $field3) } } List { ForEach(1..<6) { index in Text("Item \(index)") } } .listStyle(InsetListStyle()) } .navigationTitle("Form and List View") .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Dismiss") { // Handle dismiss action } .foregroundStyle(.red) // } ToolbarItem(placement: .primaryAction) { Button("Done") { // Handle done action } .foregroundStyle(.green) // } } } } I can't customize the color of the Buttons. Besides .foreground modifier I have tried ..foregroundColor(.red) and .foregroundColor(.green) to no avail. How can I customize the buttons in the toolbar for both macOS and IOS
Replies
3
Boosts
0
Views
1.1k
Activity
Aug ’23
SwiftChart with secondary Y Axis
I created a SwiftChart as below and I would like to have two YAxis, one for amount and the second for count. So, the amount YAxis is a different scale then the count YAxis. Does anybody have an example of this or shed some light on coding two different YAxis? Thanks ForEach(seriesArt) { series in ForEach(series.chartSeries.chartEntry) { BarMark( x: .value("Tier", $0.tier), y: .value("Price", $0.keyValue) ) } .foregroundStyle(by: .value("Count", series.chartCategory)) .position(by: .value("Price", series.chartCategory)) } } .frame(width: 400, height: 200) .chartXAxis { AxisMarks(position: .bottom, values: .automatic) { AxisValueLabel() .foregroundStyle(Color.white) } } .chartYAxis { AxisMarks(position: .leading, values: .automatic) { value in AxisGridLine(centered: true, stroke: StrokeStyle(lineWidth: 1)) AxisValueLabel() { if let intValue = value.as(Int.self) { Text("\(intValue)") .font(.system(size: 10)) .foregroundColor(.white) } } } .chartYAixs - for count sum by tier which needs to be a different scale from the amount YAxis } } }
Replies
1
Boosts
0
Views
1.1k
Activity
Apr ’24