I am adopting some of the new glass UI, but having to duplicate a lot of code to maintain support for previous UI systems in macOS. An example:
if #available(macOS 26.0, *) {
VStack {
/*some 40+ lines of code clipped here for brevity*/
}
.cueButtons()
.cueStyleGlass()
} else {
VStack {
/*identical 40+ lines of code clipped here for brevity*/
}
.cueButtons()
.cueStyle()
}
If I try to use conditional modifiers as indicated here:
extension View {
func cueStyle(font: Font = .system(size: 45)) -> some View {
if #available(macOS 26.0, *) {
modifier(GlassCueStyle(font: font))
} else {
modifier(CueStyle(font: font))
}
}
}
I get this error:
Conflicting arguments to generic parameter 'τ_1_0' ('ModifiedContent<Self, GlassCueStyle>' vs. 'ModifiedContent<Self, CueStyle>')
Is there a better way to do this?
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Created
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.
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.