My environment is as follows:
Xcode 12, macOS BS developing a macOS app.
I have an IBOutlet from a IB window as
@IBOutlet weak var imageView: NSImageView!
So, I want to store imageView to a NSData object and then save the NSData object in my UserDefaults.
Once I saved the Image in my UserDefaults I need to be able to decode or retrieve the image for use in other parts of the app.
How is this done?
Also, I have seen some cautions about converting an Image to NSData object and retrieving. It seems the retrieved image may not be 100% as it was originally. Is this true and if so why?
Thanks
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I connected Github to Xcode 13.2 (Monterey macOS) successfully, however I do not see any packages available when I select Github as the source.
I did download Xcode 13.2 from the developers website and it did fix some problems I was having with Xcode from the App Store but did make any difference to the issue above.
Anybody else have this issue with Xcode 13.2?
How do you activate the Printer Panel using a toolbar printer Icon in a macOS app like you get when I select File -> Print (CMD-P)? This is in a tableView view based screen.
I have connected the first responder to "print:" thinking this might work but the printer Icon in the toolbar remains grayed-out. Also, tried connecting it to a @IBAction func but it still is grayed out.
I am using Xcode 13 and 14 beta
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?
I would like customize the nstableview alternate row color as light blue instead og light gray.
How is this done?
thanks
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()
}
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
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?
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
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
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
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
}
}
}
Using Interface Builder with Xcode 11 I have created two windows, when I activate the second window it opens as a tab in the main window. How do I change this to start a second window instead of a tab?
I have been looking for information on how to implement NSSpellChecker and NSTextCheckingController the last couple of days and have come up empty. Does anybody of some information using these two AppKit API's or even better an example on using them with an IBOutlet text field?
I understand Apple use to make available the source code for textEdit app? Does anybody know if this is still the case?
Thanks
I have a test app with a tableView that has a comboBoxCell for one of the columns in Xcode 12:
The view controller code is as follows:
//
// ViewController.swift
// ComboBoxExample
//
// Copyright © 2016 yourCompany. All rights reserved.
//
import Cocoa
class ViewController: NSViewController, NSComboBoxCellDataSource {
var states = ["Alabama", "Alaska", "Arizona", "Arkansas", "California", "Colorado", "Connecticut", "Delaware",
"Florida", "Georgia", "Hawaii", "Idaho", "Illinois", "Indiana", "Iowa", "Kansas", "Kentucky",
"Louisiana", "Maine", "Maryland", "Massachusetts", "Michigan", "Minnesota", "Mississippi",
"Missouri", "Montana", "Nebraska", "Nevada", "New Hampshire", "New Jersey", "New Mexico",
"New York", "North Carolina", "North Dakota", "Ohio", "Oklahoma", "Oregon", "Pennsylvania",
"Rhode Island", "South Carolina", "South Dakota", "Tennessee", "Texas", "Utah", "Vermont",
"Virginia", "Washington", "West Virginia", "Wisconsin", "Wyoming"]
@IBOutlet weak var itemComboCell: NSComboBoxCell!
override func viewDidLoad() {
super.viewDidLoad()
itemComboCell.usesDataSource = true
itemComboCell.dataSource = self
self.itemComboCell.completes = true
// Do any additional setup after loading the view.
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
func numberOfItemsInComboBoxCell(in comboBoxCell: NSComboBoxCell) - Int {
// anArray is an Array variable containing the objects
return states.count
}
func comboBoxCell(_ comboBoxCell: NSComboBoxCell, objectValueForItemAt index: Int) - Any {
return (states[index])
}
}
When running the example I get the following error:
2021-03-05 15:16:29.940373-0600 ComboBoxExample[40515:1914724] *** Illegal NSComboBoxCell data source (ComboBoxExample.ViewController: 0x600000e501b0). Must implement numberOfItemsInComboBoxCell: and comboBoxCell:objectValueForItemAtIndex:
How do I resolve this?