Post

Replies

Boosts

Views

Activity

Configure document used by my swiftui document app
Trying to configure info.plist and the base application the application works with the application. I consistently get two errors. Validation failed Disallowed UTTypes value. The Info.plist key 'UTTypeIdentifier' under 'UTImportedTypeDeclarations' in 'Blood Pressure Management V2.0.app' has disallowed values '[com.example.item-document]'. A Uniform Type Identifier starting with one of the patterns in the list '( "com.example." )' is disallowed. (ID: f2dbfe04-4f06-47ac-b74f-28ec238238c4) Validation failed The product archive is invalid. The value of the CFBundleDocumentTypes key in the Info.plist must be an array of dictionaries, with each dictionary containing at least the CFBundleTypeName key. (ID: fad3e65a-dc9d-4d9e-9506-703b874f71c6) Is there any clear documentation with examples? I have not found it yet.
0
0
49
Aug ’25
Install HelpBook in application
The Apple documentation is from the 10.6 era and appears to be not correct for the modern OS. I have the help book prepared as a html document. What needs to be done to take this html document (html text and in the same directory a directory with all the image files. In Firefox the html document displays correctly. What modifications are necessary for the html document? And where do I lace this in the application bundle?
2
0
67
Aug ’25
Copy file in application document file to user Documents file
I ave an application that makes use of charts. I would like to have a button for the user to save the chart as a PDF. I tried to have the button save the PDF to the user's document directory directly. That attempt failed. But I was able to save the PDF to the application sandboxed documents directory. The question is how to programmatically move that file from the application documents folder to the user's general documents folder. So far I have not been able to find a method that will move the PDF file. Any ideas?
2
0
314
Sep ’25
Save SwiftData object for model with one to many relationship
First the Model: import Foundation import SwiftData //Model for Earned Value Analysis @Model final class CostReport{ var aCWP: Double //Actual Cost of Work Performed var bCWP: Double //Budgeted Cost of Work Performed var bCWS: Double // Budgeted Cost of Work Scheduled var cumACWP: Double// Cumlative Actual Cost of Work Performed var cumBCWP: Double // Cumlative Budgeted Cost of Work Performed var cumBCWS: Double // Cumlative Budgeted Cost of Work Scheduled var startDateOfPeriod: Date var endDateOfPeriod: Date var contract: Contract? init(aCWP: Double = 0.0, bCWP: Double = 0.0, bCWS: Double = 0.0, cumACWP: Double = 0.0, cumBCWP: Double = 0.0, cumBCWS: Double = 0.0, startDateOfPeriod: Date = .now, endDateOfPeriod: Date = .now, contract: Contract) { self.aCWP = aCWP self.bCWP = bCWP self.bCWS = bCWS self.cumACWP = cumACWP self.cumBCWP = cumBCWP self.cumBCWS = cumBCWS self.startDateOfPeriod = startDateOfPeriod self.endDateOfPeriod = endDateOfPeriod self.contract = contract } } @Model //Model for Contracts final class Contract{ var costReports: [CostReport] var contractType: ContractType? @Attribute(.unique)var contractNumber: String @Attribute(.unique)var contractName: String var startDate: Date var endDate: Date var contractValue: Double var contractorName: String var contractorContact: String var contractorPhone: String var contractorEmail: String init(costReports: [CostReport], contractType: ContractType, contractNumber: String = "", contractName: String = "", startDate: Date = .now, endDate: Date = .now, contractValue: Double = 0.0, contractorName: String = "", contractorContact: String = "", contractorPhone: String = "", contractorEmail: String = "") { self.costReports = costReports self.contractType = contractType self.contractNumber = contractNumber self.contractName = contractName self.startDate = startDate self.endDate = endDate self.contractValue = contractValue self.contractorName = contractorName self.contractorContact = contractorContact self.contractorPhone = contractorPhone self.contractorEmail = contractorEmail } } @Model //Model for contract types final class ContractType{ var contracts: [Contract] @Attribute(.unique)var typeName: String @Attribute(.unique)var typeCode: String var typeDescription: String init(contracts: [Contract], typeName: String = "", typeCode: String = "", typeDescription: String = "") { self.contracts = contracts self.typeName = typeName self.typeCode = typeCode self.typeDescription = typeDescription } } ContractType has a one to many relationship to Contract. Contract has a one to many relationship with CostReport. The ContractTypes can vary depending on the users situation so I need the user to be able to enter ContractTypes. Code for that: import SwiftUI import SwiftData struct EnterContractTypes: View { @Environment(.modelContext) var managedObjectContext @Query private var contracts: [Contract] @Query private var contractTypes: [ContractType] @State private var typeName: String = "" @State private var typeCode: String = "" @State private var typeDescription: String = "" var body: some View { Form { Section(header: Text("Enter Contract Type") .foregroundStyle(Color(.green)) .bold() .font(.largeTitle)) { TextField("Name", text: $typeName) .frame(width: 400, height: 40) TextField("Code", text: $typeCode) .frame(width: 400, height: 40) TextField("Description", text: $typeDescription, axis: .vertical) .frame(width: 600, height: 60) } } .frame(width:1000, height:500) } func save() { let newContractType = ContractType(context: managedObjectContext) newContractType.typeName = typeName newContractType.typeCode = typeCode newContractType.typeDescription = typeDescription try? managedObjectContext.save() The "let newContractType = ContractType(context: managedObjectContext)" is where the error happens. It says there is an extra argument in the context call.
4
0
237
Sep ’25
Picker using SwiftData
I am attempting to impliment a a Picker that uses SwiftData to fill in the choices. I am missing something because I can get the picker to appear with the proper selections but the picker does not register my choice (no check mark appears and the text in the picker window is blank after I move to the next field. The model import Foundation import SwiftData //Model one: type of contract, i.e. Firm Fixed Price, etc @Model final class TypeOfContract { var contracts: [Contract] @Attribute(.unique) var typeName: String @Attribute(.unique) var typeCode: String var typeDescription: String init(contracts: [Contract], typeName: String = "", typeCode: String = "", typeDescription: String = "") { self.contracts = contracts self.typeName = typeName self.typeCode = typeCode self.typeDescription = typeDescription } } //Model two: the Contract @Model final class Contract { var contractType: TypeOfContract? var costReports: [CostReport] @Attribute(.unique) var contractNumber: String @Attribute(.unique) var contractName: String var startDate: Date var endDate: Date var contractValue: Decimal var contractCompany: String var contractContact: String var contactEmail: String var contactPhone: String var contractNotes: String init(contractType: TypeOfContract? = nil, costReports: [CostReport], contractNumber: String = "", contractName: String = "", startDate: Date = .now, endDate: Date = .now, contractValue: Decimal = 0.00, contractCompany: String = "", contractContact: String = "", contactEmail: String = "", contactPhone: String = "", contractNotes: String = "") { self.contractType = contractType self.costReports = costReports self.contractNumber = contractNumber self.contractName = contractName self.startDate = startDate self.endDate = endDate self.contractValue = contractValue self.contractCompany = contractCompany self.contractContact = contractContact self.contactEmail = contactEmail self.contactPhone = contactPhone self.contractNotes = contractNotes } } //Model Three: The Cost Reports @Model final class CostReport { var contract: Contract? var periodStartDate: Date var periodEndDate: Date var bCWP: Double //Budgeted Cost Work Performed var aCWP: Double //Actual Cost Work Performed var bCWS: Double //Budgeted Cost Work Scheduled //Calculated fields init(contract: Contract? = nil, periodStartDate: Date = .now, periodEndDate: Date = .now, bCWP: Double = 0.0, aCWP: Double = 0.0, bCWS: Double = 0.0) { self.contract = contract self.periodStartDate = periodStartDate self.periodEndDate = periodEndDate self.bCWP = bCWP self.aCWP = aCWP self.bCWS = bCWS } } The Swift Code for the input form import SwiftData struct EnterNewContract: View { @Environment(\.modelContext) var modelContext @Query(sort: \TypeOfContract.typeCode) private var typeOfContracts: [TypeOfContract] @Query private var contracts: [Contract] @State private var costReports: [CostReport] = [] @State private var contractType: [TypeOfContract] = [] @State private var contractNumber: String = "" @State private var contractName: String = "" @State private var startDate: Date = Date() @State private var endDate: Date = Date() @State private var contractValue: Decimal = 0 @State private var contractCompany: String = "" @State private var contractContact: String = "" @State private var contactEmail: String = "" @State private var contactPhone: String = "" @State private var contractNotes: String = "" var body: some View { Form { VStack { Section(header: Text("Enter New Contract") .foregroundStyle(.green) .font(.headline)){ Picker("Select a type of contract", selection: $contractType) { ForEach(typeOfContracts, id: \.self) { typeOfContracts in Text(typeOfContracts.typeCode) .tag(contractType) } } TextField("Contract Number", text: $contractNumber) .frame(width: 800, height: 40) TextField("Contract Name", text: $contractName) .frame(width: 800, height: 40) DatePicker("Contract Start Date", selection: $startDate, displayedComponents: [.date]) DatePicker("Contract End Date", selection: $endDate, displayedComponents: [.date]) } } } } }
3
0
175
Oct ’25
Present User an error message when SwiftData save fails
Have a data model that sets certain fields as unique. If the user attempts to save a duplicate value, the save fails quietly with no indication to the user that the save failed. The program is on Mac OS 26.0.1 @Environment(\.modelContext) var modelContext @Query private var typeOfContracts: [TypeOfContract] @State private var typeName: String = "" @State private var typeCode: String = "" @State private var typeDescription: String = "" @State private var contracts: [Contract] = [] @State private var errorMessage: String? = "Data Entered" @State private var showAlert: Bool = false var body: some View { Form { Text("Enter New Contract Type") .font(.largeTitle) .foregroundStyle(Color(.green)) .multilineTextAlignment(.center) TextField("Contract Type Name", text: $typeName) .frame(width: 800, height: 40) TextField("Contract Type Code", text: $typeCode) .frame(width: 800, height: 40) Text("Contract Type Description") TextEditor(text: $typeDescription) .frame(width: 800, height: 200) .scrollContentBackground(.hidden) .background(Color.teal) .font(.system(size: 24)) Button(action: { self.saveContractType() }) { Text("Save new contract type") } } } func saveContractType() { let typeOfContract = TypeOfContract(contracts: []) typeOfContract.typeName = typeName typeOfContract.typeCode = typeCode typeOfContract.typeDescription = typeDescription modelContext.insert(typeOfContract) do { try modelContext.save() }catch { errorMessage = "Error saving data: \(error.localizedDescription)" } } } I have tried to set alerts but Xcode tells me that the alerts are not in scope
10
0
283
Oct ’25
Swiftui Picker with optional value selected in picker
First the model: import SwiftData //Model one: type of contract, i.e. Firm Fixed Price, etc @Model final class TypeOfContract { var contracts: [Contract] @Attribute(.unique) var typeName: String @Attribute(.unique) var typeCode: String var typeDescription: String init(contracts: [Contract], typeName: String = "", typeCode: String = "", typeDescription: String = "") { self.contracts = contracts self.typeName = typeName self.typeCode = typeCode self.typeDescription = typeDescription } } //Model two: the Contract @Model final class Contract { var contractType: TypeOfContract? var costReports: [CostReport] @Attribute(.unique) var contractNumber: String @Attribute(.unique) var contractName: String var startDate: Date var endDate: Date var contractValue: Decimal var contractCompany: String var contractContact: String var contactEmail: String var contactPhone: String var contractNotes: String init(contractType: TypeOfContract?, costReports: [CostReport], contractNumber: String = "", contractName: String = "", startDate: Date = .now, endDate: Date = .now, contractValue: Decimal = 0.00, contractCompany: String = "", contractContact: String = "", contactEmail: String = "", contactPhone: String = "", contractNotes: String = "") { self.contractType = contractType self.costReports = costReports self.contractNumber = contractNumber self.contractName = contractName self.startDate = startDate self.endDate = endDate self.contractValue = contractValue self.contractCompany = contractCompany self.contractContact = contractContact self.contactEmail = contactEmail self.contactPhone = contactPhone self.contractNotes = contractNotes } } //Model Three: The Cost Reports @Model final class CostReport { var contract: Contract? var periodStartDate: Date var periodEndDate: Date var bCWP: Double //Budgeted Cost Work Performed var aCWP: Double //Actual Cost Work Performed var bCWS: Double //Budgeted Cost Work Scheduled //Calculated fields init(contract: Contract?, periodStartDate: Date = .now, periodEndDate: Date = .now, bCWP: Double = 0.0, aCWP: Double = 0.0, bCWS: Double = 0.0) { self.contract = contract self.periodStartDate = periodStartDate self.periodEndDate = periodEndDate self.bCWP = bCWP self.aCWP = aCWP self.bCWS = bCWS } } Now the code for the Picker ```import SwiftUI import SwiftData struct EnterNewContract: View { @Environment(\.modelContext) var modelContext @Query(sort: \TypeOfContract.typeName) private var typeOfContracts: [TypeOfContract] @Query private var contracts: [Contract] @State private var costReports: [CostReport] = [] @State private var contractType: [TypeOfContract]? @State private var contractNumber: String = "" @State private var contractName: String = "" @State private var startDate: Date = Date() @State private var endDate: Date = Date() @State private var contractValue: Decimal = 0 @State private var contractCompany: String = "" @State private var contractContact: String = "" @State private var contactEmail: String = "" @State private var contactPhone: String = "" @State private var contractNotes: String = "" var body: some View { Form { VStack { Section(header: Text("Enter New Contract") .foregroundStyle(.green) .font(.headline)){ Picker("Select a type of contract", selection: $contractType) {Text("Select type").tag(nil as TypeOfContract?) ForEach(typeOfContracts, id: \.self) { typeOfContracts in Text(typeOfContracts.typeName) .tag(typeOfContracts as TypeOfContract?) } } TextField("Contract Number", text: $contractNumber) .frame(width: 800, height: 40) TextField("Contract Name", text: $contractName) .frame(width: 800, height: 40) DatePicker("Contract Start Date", selection: $startDate, displayedComponents: [.date]) DatePicker("Contract End Date", selection: $endDate, displayedComponents: [.date]) } } } } } The code works, for the most part. The selection I make from the list does not appear. Instead there is just a shaded empty box . Also, I need to select my selection choice twice before the check mark to appear. To see the choices and my selection I must click on the empty shaded box. What did I do wrong
2
0
204
Oct ’25
Adding days to a date using the result of a division operation
var testTwo: Double = 0 testDouble = 80 testTwo = 200 var testThree: Int = 0 testThree = Int(testTwo/testDouble) var testDate: Date = .now var dateComponent = DateComponents() dateComponent.day = testThree var newDate: Date = Calendar.current.date(byAdding: dateComponentwith a thread error , to: testDate)! This code works in a playground. However, when I try to use it in Xcode for my app it fails with the following error: Thread 1: Fatal error: Double value cannot be converted to Int because it is either infinite or NaN I printed the value being converted to Int and it was not NAN or infinite.
2
0
750
Nov ’25