Post not yet marked as solved
Learn
It would be best if you could learn about Binding, there is a convenient propertyWrapper @Binding
Refer: https://developer.apple.com/documentation/swiftui/binding/
Sample code
struct ContentView: View {
//This is using the Binding propertyWrapper
@Binding var data: [TodoItem]
var body: some View {
List {
ForEach($data) { datum in
TableRow(data: datum) // <- what goes here?
.swipeActions {
Button(role: .destructive) {
data.delete(datum) //data.removeAll { $0 == datum.wrappedValue }
} label: {
Label("Delete", systemImage: "trash")
}
}
}
}
}
}
Short answer
If you are using Binding<SomeType>, then use wrappedValue
If you are using @Binding propertyWrapper then using just the variable name should give the value
Long Answer
import SwiftUI
struct Something {
//This is using the Binding propertyWrapper
@Binding var price1: Int
func f1() {
price1 //Int value
$price1 //Binding to the Int
let price2 = $price1 //Type of price2 is Binding<Int>
price2.wrappedValue //Int value
}
}
Post not yet marked as solved
@WeagleWeagle
I have a scenario in which the initialiser to the view passes a value and depending on the value I need to determine the predicate and sort descriptors.
Currently I have an if else statement and then I am setting self._items as suggested by @aharriscrowne
For that scenario, is it ok to set self._items in the initialiser?
Confusion about NavigationSplitView
There seem to be 2 ways:
Option 1: WWDC video (https://developer.apple.com/wwdc22/10054) uses NavigationLink for NavigationSplitView
Option 2: Documentation (https://developer.apple.com/documentation/swiftui/navigationsplitview) they don't use NavigationLink
Not sure what is the correct approach, using NavigationLink seems to require navigationDestination but that doesn't sit well with NavigationSplitView as the destination view is specified part of the detail closure and repeating the code would be redundant.
Following the documentation (without NavigationLink):
Following https://developer.apple.com/documentation/swiftui/navigationsplitview documentation things seem to work ok, there is only one warning thrown (as opposed to 3 before):
Update NavigationAuthority bound selection tried to update multiple times per frame.
The other 2 warnings about navigationDestination and Focus are not thrown
I really wish someone from the Apple team could clarify on this, please.
The key is to use a Label for it to work on macOS
example:
Text("aaa")
.swipeActions {
Button {
//Do something
} label: {
Label("Delete", systemImage: "trash") //Use a label
}
Post not yet marked as solved
My scenario
I had merged a lot of changes from a branch (pull request)
I had also made changes to the swift package
Problem
Export archive for app-store distribution
Command exited with non-zero exit-code: 70
Solution / Workaround
Cleared DerivedData
Cloned the project in a disk location
Post not yet marked as solved
I am not sure I understand your question correctly, contextMenu could be added to any custom view
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.padding()
.contextMenu {
Button("aaa") {}
}
}
}
Post not yet marked as solved
Use a ZStack instead of overlay
ZStack {
Text("Hello, world!")
.padding()
Rectangle()
.fill(.red)
}
Post not yet marked as solved
Remove Selection
Can you set selectedRecipe = nil, that should remove any selection of the recipe.
Selection of recipe is driven by the state variable selectedRecipe so depending on the value different recipes
Reference:
https://developer.apple.com/documentation/swiftui/list
Post not yet marked as solved
I have filed a feedback FB9793368
DTS has confirmed this is a bug, hope it gets fixed, fingers crossed
Post not yet marked as solved
I think What's new in SwiftUI talk explains this https://developer.apple.com/wwdc22/10052 (11:39)
https://developer.apple.com/documentation/swiftui/radialgradient/presentationdetents(_:)
Post not yet marked as solved
Thanks a lot Quinn!!!
The following don't seem to be working for me:
Upvoting an answer, shows as upvoted but when I signout the upvote doesn't show as upvoted
Email notification as mentioned above don't work even selected
Also it would be nice to have email notifications checked by default for the question you ask, as most people would expect that by default.
IMHO improving the website can directly improve the engagement with in the developers as more people will use the forums and more questions would get asked and answered.
Post not yet marked as solved
Selection:
You need maintain a @State variable for selection and pass it to List's selection parameter as a binding
To restore selection state across app launches use @SceneStorage
All you need is shown in the video link below, watch it slowly and understand the concepts
Console Warnings
onChange(of: UpdateTrigger) action tried to update multiple times per frame
A NavigationLink is presenting a value of type "Category" but there is no matching navigation destination visible from the location of the link. The link cannot be activated.
Feedback has been submitted for the above mentioned warnings and Apple Engineers are aware of this bug, so you can ignore it for now
MacOS Sidebar
You can tap on the sidebar button to open the sidebar
I think there is an option in NavigationSplitView configuration, you need to check the documentation columnVisibility but I haven't mentioned to get it working
Reference:
Please watch https://developer.apple.com/wwdc22/10054
It has sample code to do exactly what you want (you can copy code by clicking on the code tab)
Post not yet marked as solved
Could you check https://developer.apple.com/documentation/swiftui/view/navigationsplitviewcolumnwidth(_:)
Based on the Apple Engineer's response this is a bug, I have also filed feedback and mentioned it.