Post

Replies

Boosts

Views

Activity

Reply to How to handle adding and removing items from NavigationSplitView
@Vision Pro Engineer How would you select the last item that is being stored with SwiftData? @Environment(\.modelContext) private var modelContex ```t @Query private var applicants: [Applicant] @State private var newApplicant: Applicant? @State private var selection: Applicant? /// if !applicants.isEmpty { List (selection: $selection) { ForEach(applicants) { applicant in NavigationLink { ApplicantView(applicant: applicant) /// private func addApplicant() { withAnimation { let newItem = Applicant() modelContext.insert(newItem) newApplicant = newItem selection = applicants.last } } ''' I have it setup this way but the behavior has not changed. :-) Thank you again for your help!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Jun ’24
Reply to TabItem Not Respected In TabView
Hello @Claude31 and @Vision Pro Engineer , thank you both for your responses. Things have been busy, and unfortunately, I wasn't able to respond. I have made these changes to both my beta app as well as tested it with the sample code provided. It appears to run fine in a simulator, but then whenever I run it on my Mac or run it on an iOS device, it seems to not be tracking the selected item. The screenshots from the Mac window are showing the issue when running in a real window, and the iOS screenshots are from the simulator. This will result in having an issue where if I click on another window, such as Safari, then the test app will return to the first tab. I am using SwiftData in its default state, but since it's not tracking anything in the sample app, I don't think that is the issue. Any ideas on what I could be doing wrong? (This is being run with the latest Xcode Beta for iOS 18, and has been this way since I originally wrote my post.) Thank you all again for any help you can offer, and I really appreciate your responses. :-) @State private var selectedIndex = 0 var body: some View { Text("\(selectedIndex)") TabView(selection: $selectedIndex) { View1() .tabItem {Label("Tab 1", systemImage: "dollarsign.gauge.chart.leftthird.topthird.rightthird")} .tag(0) View2() .tabItem {Label("Tab 2", systemImage: "dollarsign.gauge.chart.leftthird.topthird.rightthird")} .tag(1) } } } #Preview { ContentView() .modelContainer(for: Item.self, inMemory: true) }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24
Reply to How to handle adding and removing items from NavigationSplitView
@Vision Pro Engineer you are all over helping me! :-) I'm sorry if I'm not the best at providing the requested information, still very new to programming. I added the print statement, and It prints "ApplicantProcessor.Applicant" whenever adding. I would be happy to show how the NavigationSplitView is setup. Here is that file. struct FilteredApplicantListView: View { @State private var searchText = "" var body: some View { NavigationSplitView { ApplicantListView(applicantFilter: searchText) .searchable(text: $searchText, prompt: "Enter Name, Email, or Phone Number") .autocorrectionDisabled(true) } detail: { } } } Here is my app file struct ApplicantProcessorApp: App { var sharedModelContainer: ModelContainer = { let schema = Schema([ Applicant.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() } .modelContainer(sharedModelContainer) } } Here is what an Applicant looks like import Foundation import SwiftData @Model final class Applicant { var name = "" var email = "" var phoneNumber = "" var applicationDate = Date.now var expirationDate: Date { return Calendar.current.date(byAdding: .day, value: 90, to: applicationDate)! } private var _applicationStatus: ApplicationStatus? var applicationStatus: ApplicationStatus { get { return _applicationStatus ?? .defaultState } set { _applicationStatus = newValue } } private var _applicantType: ApplicantType? var applicantType: ApplicantType { get { return _applicantType ?? .standard } set { _applicantType = newValue } } private var _additionalFinancialRequirements: FinancialStatuses? var additionalFinancialRequirements: FinancialStatuses { get { return _additionalFinancialRequirements ?? .defaultState } set { _additionalFinancialRequirements = newValue } } var coSignerApplicants = "" var coSigners = "" var applicantAppFolioURL = "" var property = "" var notes = "" var requestedItems = "" var photoID = false var incomeDocumentation = false var employmentRequirement = false var studentDocumentation = false var ssnVerification = false var backgroundCheck = false var evictionCheck = false var stateCheck = false var noPastDueBalances = false var noGeneralCollections = false var dtiApprovable = false var creditScoreInRange = false var noCosignerOrDoubleDepositRequired = false var ableToScore = false var creditScore = 0 var additionalApplicant = false var additionalApplicantNames = "" var additionalApplicantAppFolioLink = "" private var _petType: PetType? var petType: PetType { get { return _petType ?? .defaultState } set { _petType = newValue } } var petTypeCompatitable = false var petScreeningComplete = false var oldPetTypeCheck = false var declineReasons = "" init(name: String = "", email: String = "", phoneNumber: String = "", applicationDate: Date = Date.now, _applicationStatus: ApplicationStatus? = .defaultState, _applicantType: ApplicantType? = .standard, _additionalFinancialRequirements: FinancialStatuses? = .defaultState, coSignerApplicants: String = "", coSigners: String = "", applicantAppFolioURL: String = "", property: String = "", notes: String = "", requestedItems: String = "", photoID: Bool = false, incomeDocumentation: Bool = false, employmentRequirement: Bool = false, studentDocumentation: Bool = false, ssnVerification: Bool = false, backgroundCheck: Bool = false, evictionCheck: Bool = false, stateCheck: Bool = false, noPastDueBalances: Bool = false, noGeneralCollections: Bool = false, dtiApprovable: Bool = false, creditScoreInRange: Bool = false, noCosignerOrDoubleDepositRequired: Bool = false, ableToScore: Bool = false, creditScore: Int = 0, additionalApplicant: Bool = false, additionalApplicantNames: String = "", additionalApplicantAppFolioLink: String = "", _petType: PetType? = .defaultState, petTypeCompatitable: Bool = false, petScreeningComplete: Bool = false, oldPetTypeCheck: Bool = false, declineReasons: String = "") { self.name = name self.email = email self.phoneNumber = phoneNumber self.applicationDate = applicationDate self._applicationStatus = _applicationStatus self._applicantType = _applicantType self._additionalFinancialRequirements = _additionalFinancialRequirements self.coSignerApplicants = coSignerApplicants self.coSigners = coSigners self.applicantAppFolioURL = applicantAppFolioURL self.property = property self.notes = notes self.requestedItems = requestedItems self.photoID = photoID self.incomeDocumentation = incomeDocumentation self.employmentRequirement = employmentRequirement self.studentDocumentation = studentDocumentation self.ssnVerification = ssnVerification self.backgroundCheck = backgroundCheck self.evictionCheck = evictionCheck self.stateCheck = stateCheck self.noPastDueBalances = noPastDueBalances self.noGeneralCollections = noGeneralCollections self.dtiApprovable = dtiApprovable self.creditScoreInRange = creditScoreInRange self.noCosignerOrDoubleDepositRequired = noCosignerOrDoubleDepositRequired self.ableToScore = ableToScore self.creditScore = creditScore self.additionalApplicant = additionalApplicant self.additionalApplicantNames = additionalApplicantNames self.additionalApplicantAppFolioLink = additionalApplicantAppFolioLink self._petType = _petType self.petTypeCompatitable = petTypeCompatitable self.petScreeningComplete = petScreeningComplete self.oldPetTypeCheck = oldPetTypeCheck self.declineReasons = declineReasons } static let sampleData = [ Applicant(name: "John Doe", email: "johndoe@icloud.com", phoneNumber: "123-456-8897", _applicationStatus: .defaultState) ] }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24
Reply to TabItem Not Respected In TabView
Hello @Vision Pro Engineer I created a GitHub project for it which I believe is setup the way we have discussed. You can see the error if you run it natively on your iOS or iPadOS device, or if you run for the Mac on an M1 device. It cannot be in the Simulator. You will see that in the simulator it functions as expected, however whenever run on a device it does not track the selected tab. https://github.com/erfind/TestTabs
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Aug ’24