The SwiftUI Navigation structures work in ways that are not intuitive to me. For example, I am trying to display a set of data that represents rankings contained in a balloting system that I have created. The ballots all have candidates that are ranked from highest preference to lowest.
Normally, I try to work backwards in SwiftUI, so I built the ballot editor to take a binding to the ballot itself:
struct BallotEditor: View {
@Binding var ballot: Election.Ballot
var maxRank: Int
var body: some View {
VStack {
ForEach($ballot.rankings) { $ranking in
CandidateRankingPicker(maxRanking: maxRank, ranking: $ranking)
}
}
}
}
This is embedded into a view with a list of ballots:
struct BallotsView: View {
@Binding var document: ElectionDocument
var body: some View {
List($document.ballots) { $ballot in
NavigationLink {
BallotEditor(ballot: $ballot, maxRank: document.election.candidates.count)
.padding()
} label: {
BallotListElementView(ballot: ballot)
}
}
}
}
This portion works in the editor. When the ballot is selected, the editor populates the selected candidate choices, and the editing works.
However, when I attempt to insert BallotsView into a TabView, the NavigationLink stops working as expected. I didn't think NavigationLink was the proper way to do this, but it had been working.
TabView {
Tab("Ballots", systemImage: "menucard") {
BallotsView(document: $document)
}
Tab {
CandidateView()
} label: {
Text("Candidates")
}
.tabViewStyle(.sidebarAdaptable)
}
This is my third iteration. I have tried using a List with selection, but in that case, I am unable to pass the binding to the detail view. I just don't understand how this works, and I am preparing a version in Cocoa so that I don't have to deal with it anymore.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
I'm currently working on transitioning to StoreKit 2. In order to see if my users are legacy users who purchased the app before I implemented an in-app purchase, I am trying to use the original purchase date for the app. Unfortunately, it's returning 0 seconds since 1970.
func updateOriginalPurchaseStatus() async throws {
let transaction = try await checkVerified(AppTransaction.shared)
self.originalPurchaseVersion = transaction.originalAppVersion
self.originalPurchaseDate = transaction.originalPurchaseDate
}
This is from the transaction:
[3] = {
key = "originalPurchaseDate"
value = number (number = 0)
}
Currently trying to figure out when I actually purchased the app, but it might be as early as 2012. And I likely used a download code.