Is it possible to have conditional table columns for a swifui Table statement?
Like for this code
TableColumn("Image") { artPiece in
if let imageData = artPiece.artImage.first, let image = UIImage(data: imageData!) {
Image(uiImage: image)
.resizable()
.frame(width: 50, height: 50)
} else {
Image(systemName: "photo")
.resizable()
.frame(width: 50, height: 50)
}
}
.customizationID("Image")
TableColumn("Name", value: \.artName)
.customizationID("Name")
TableColumn ("Art ID", value: \.artPieceID) { artPiece in
Text(String(artPiece.artPieceID))
}
.customizationID("Art ID")
have a conditional TableColumn for this part of my SWIFTDATA model
var artDefinedFields: [ArtDefinedFields] = [] or if I change the variable string array to this var artDefinedFields: [ArtDefinedFields] = Array(repeating: ArtDefinedFields(), count: 10), initialize the array with "None" and only create a TableColumn when there is aArtDeginedFields value other than "None"
Post
Replies
Boosts
Views
Activity
This code which works fine on macOS Sonoma but on Sequoia the navigationLinks do not work?
VStack {
Text("Application Global Values")
.font(.largeTitle)
.fontWeight(.bold)
.padding(.bottom, 10)
Text("Select each of the Descriptors, enter the values and when done then Tap on (Add/Save)")
.font(.title3)
.foregroundColor(.secondary)
List {
NavigationLink("Enter Core Descriptors", destination: CoreView(systemSettings: $systemSettings))
.padding() // Add padding to create some space inside the border
// .background(Color.white) // Optional: Add a background color if needed
// .border(Color.red, width: 2) // Add a red border with a specified thickness
.overlay(
RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners
.stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border
)
SetupDivider(thickness: 3)
NavigationLink("Enter Counters Descriptors", destination: CountersView(systemSettings: $systemSettings))
.padding()
// .background(Color.white)
.overlay(
RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners
.stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border
)
SetupDivider(thickness: 3)
NavigationLink("Create Custom Descriptors", destination: UserFieldsView(userFields: $userFields))
.padding()
// .background(Color.white)
.overlay(
RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners
.stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border
)
SetupDivider(thickness: 3)
NavigationLink("View All Descriptors", destination: DefaultDetailView(userFields: $userFields, systemSettings: $systemSettings))
.padding()
// .background(Color.white)
.overlay(
RoundedRectangle(cornerRadius: 10) // Specify the corner radius for rounded corners
.stroke(Color.red, lineWidth: 2) // Define the color and thickness of the border
)
SetupDivider(thickness: 3)
}
I begin testing my IOS swiftdats Xcode 15 swift 5 on Sonoma and I am able to create my siwftdata tables as well as add records to several of the tables, Then as I proceeded with my te tables disappear and I get this error in the Xcode debug console:
error: Error: Persistent History (6) has to be truncated due to the following entities being removed: (
AppSettings,
Invoice,
Clientele,
Pay,
InvoiceItem,
TrackingArt
)
This app used to work fine and as I was making changes it started behaving in this manner. Beside the code I will supply the entire debug console with the attached file
debugConsole.txt
Here is how I have the swift data containers setup.
import SwiftData
import TipKit
import CloudKit
@main
struct ArtManagerApp: App {
@StateObject private var copyInvoiceDetails = CopyInvoiceDetails()
@StateObject private var copyPaymentDetails = CopyPaymentDetails()
@StateObject private var artTypeSettings = ArtTypeSettings()
@StateObject private var tipManager = TipManager()
// @Query(sort: \ArtPiece.artPieceID, order: .forward) private var artPieces: [ArtPiece]
// @Query(sort: \AppSettings.setID, order: .reverse) private var settingsList: [AppSettings]
var sharedModelContainer: ModelContainer = {
let schema = Schema([
ArtPiece.self, Clientele.self, TrackingArt.self, Invoice.self, InvoiceItem.self, AppSettings.self, Pay.self
])
let modelConfiguration = ModelConfiguration(schema: schema,
isStoredInMemoryOnly: false)
do {
return try ModelContainer(for: schema, configurations: [modelConfiguration])
} catch {
fatalError("Could not create ModelContainer: \(error)")
}
}()
var body: some Scene {
WindowGroup {
ContentView()
.navigationTitle("🎨 Art Manager")
.environmentObject(artTypeSettings)
.environmentObject(copyInvoiceDetails)
.environmentObject(copyPaymentDetails)
.environmentObject(tipManager) // Pass it to the ContentView
.modelContainer(sharedModelContainer)
}
}
}
class TipManager: ObservableObject {
@Published var tips: [ArtManagerTip] = []
init() {
loadTips()
}
func loadTips() {
tips = [ArtManagerTips.search_tip, ArtManagerTips.delete_tip, ArtManagerTips.extendedSearch_tip,
ArtManagerTips.searchPayments_tip, ArtManagerTips.searchArt_tip, ArtManagerTips.librarySearch_tip, ArtManagerTips.artMaintenanceSearch_tip]
}
}
class CopyPaymentDetails: ObservableObject {
@Published var payNumber: Int32 = 0
@Published var payType: String = ""
@Published var payPatronID: Int32 = 0
@Published var payPatronName: String = ""
@Published var payPatronAddress: String = ""
@Published var payPaymentAmount: Double = 0.0
@Published var payDatePayed: Date = Date()
}
class CopyInvoiceDetails: ObservableObject {
@Published var invoiceNumber: Int32 = 0
@Published var invoicePatronName: String = ""
@Published var invoicePatronPO: String = ""
@Published var invoiceDateCreated: Date = Date()
@Published var artPieceIDSaved: [Int32] = []
}
I have been testing an app which uses cloudKit with SWIFTDATA and after testing for several months my 200GB iCloud store is showing 168GB for iCloud Drive. Now my iCloud drive is only 22.6GB so the rest of the 168GB must be data from my app. Also, I have function in my app to delete all iCloud Data which I thought that should clean up iCloud storage but it does not.
I tried resetting the Develop Environment but no change to iCloud data. Also I have several other containers in iCloud created while getting iCloud working which I would like to delete but I understand you can’t.
https://forums.developer.apple.com/forums/thread/45251?answerId=788694022#788694022
Bottom line cloudkit console has been pretty much useless for me and I need a way to manage (delete containers and data). Am I missing something?
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
}
}
}
I have the following test code:
import SwiftUI
struct ContentView: View {
@State private var draggedImages: [UIImage?] = Array(repeating: nil, count: 5)
@State private var savedToDisk = false
var body: some View {
VStack {
HStack {
ForEach(0..<5, id: \.self) { index in
let image = draggedImages[index] ?? UIImage(systemName: "photo")
Image(uiImage: image!)
.resizable()
.frame(width: 80, height: 80)
.padding()
.background(Color.blue)
.foregroundColor(.white)
.cornerRadius(10)
.onDrag {
return NSItemProvider(object: UIImage(systemName: "photo")!)
}
.onDrop(of: ["public.image"], isTargeted: nil) { providers, _ in
providers.first?.loadDataRepresentation(forTypeIdentifier: "public.image") { data, error in
if let data = data, let uiImage = UIImage(data: data) {
draggedImages[index] = uiImage
saveImageToDisk(image: uiImage, imageNumber: index)
}
}
return true
}
}
.alert(isPresented: $savedToDisk) {
Alert(title: Text("Images Saved"), message: Text("The images have been saved to disk."), dismissButton: .default(Text("OK")))
}
Spacer()
}
}
.padding()
}
private func saveImageToDisk(image: UIImage, imageNumber: Int) {
if let imageData = image.pngData() {
do {
let documentsDirectory = try FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
let imageUrl = documentsDirectory.appendingPathComponent("image_\(imageNumber).png")
try imageData.write(to: imageUrl)
savedToDisk = true
} catch {
print("Error saving image: \(error)")
}
}
}
}
I can drag and drop as well as the dragged image is save on the second placeholder thru the fifth but not the first When I drag and drop to the first image another files app opens but when I close this the image is not saved. Any Ideas why the first image behaves differently to all the others?
I test on Sonoma and Xcode 15 beta 7, I wil give it a try on Ventura and Xcode 14 later today to see if the same thing happens.
Thanks
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 understand by default SwiftData uses SQLite database but it can be configured to persist data in XML, binary and even in-memory databases. Does anybody know where SwiftData the SQLite database is located?
I am getting the following error on this line of code
@Query(sort: \.id, order: .reverse) private var artList: [ArtInventory]
Cannot infer key path type from context; consider explicitly specifying a root type
So, I select fix and then the line of code then look like this
@Query(sort: \<#Root#>.id, order: .reverse) private var artList: [ArtInventory]
with this error
Invalid component of Swift key path
Some seems to have changed with the @Query macro in beta 5, which now needs a root type, but not sure how to proceed.
Any ideas how to fix?
Don't see a link to download the Xcode project, starter and complete?
How can I get it?
Thanks
Bob
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
The find and replace in project is not working for me in Xcode 14.2 on Ventura 13.2. When I enter the find text as well as the replace text the "Replace" and "Replace All" buttons remained grayed out.
Is this a bug with Xcode or am I missing something?
Please advise.
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
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 have a macOS tableview I have a textfield as a column along with an IBAction code to capture the data from this field. I wanted to add continuous spell check for this column .
So, I decided to change the column from a TextField to a ScrollView to take advantage of the continuous spell check. Using Xcode 14 I changed the Cell to a custom Cell. The custom cell has a scrollview object as the object because I want to take advantage of the built in continuous spell checking instead of using a textfield. All is well with this implementation until I tried to add a IBAction code for when I enter text in the scrollview/textView field.
There does not seem to be a way to capture the text? Am I trying to do something that can't be done or is there a way to add continuous spell check to a textField?