Hi,
I also had some problems with sheets and a Binding Bool in the past.
I would try two things.
Are you sure that the tmpEvent you set using showSheet() isn't returning an optional value that might be nil? you can try adding:
guard let tmpEvent = Event(context: viewContext) else{
print("found nil")
return
}
and if you see something in the log you know that it contains nil. This also prevents the sheet from being shown while the Event is nil.
In general I would avoid having optionals in your views because you always have to deal with optional values, or risking that your app is getting terminated because of force unwrapping.
If that doesn't work, try using an default value and see if it later on changes to the correct value. If this is the case, your sheet is presented before the event got an initial value...
Take care,
David
Post
Replies
Boosts
Views
Activity
Same here
Hi,
you could set the display mode like this:
swift
.navigationBarTitleDisplayMode(active ? .automatic : .inline)
hope this helps.
Take care,
David
Hi Kevin,
Interestingly creating the share and the SharingController wasn't too difficult. Other than that the title of the SharingController sometimes just being "Untitled" it works as expected. No idea why the title configuration is sometimes not filled in correctly.
I switched back to UIKit Lifecycle because it is just so frustrating seeing how little the SwiftUI lifecycle can do right now... I hope they will add these methods natively in future releases without the need of DelegateAdaptors.
Take care,
David
Hi,
yeah the thing with the battery widget and the forbidden background blur... Well at least for the configurable colors there is a solution. I have seen a few apps implement this feature. The easiest way I think is to use the widget configuration to give the user a list of options, and then storing the picked color. You could then get the color when building the widget, maybe UserDefaults or something like that, and set the background accordingly. The user could use the main app to edit and add colors to their list which is then displayed in the configuration...
Even though it is a hacky solution it should work.
Take care,
David
Hi,
I'm not quite sure what you mean by "pass out of loop". The "row" variable is obviously only available inside the closure because it gets reused by the loop. But you can declare a
swift
@State var name: Bool = false (or any other type)
and modify that using a button inside the loop.
Take care,
David
Hi,
When you want to perform an action when the selection changes, You should use:
.onChange(of: selection, perform: {value in
print(value)
})
And if your data in the ForEach already complies to Identifiable, you don't need to specify an id.
Hi,
As you said, LazyVStack only creates new items when needed. I don't know what your custom Scrollview looks like and I don't know why you would want a custom Scrollview if you could just change the items inside to match what you want. What does your custom Scrollview look like?
Hi,
just to add to the answer
If you want to find an item based on a condition use this: When using arrays that contain structs you can search for specific items like this:
array.firstIndex(where: {$0.ID == reference})
Hi,
Well if the code snipped I supplied didn't work it is probably a bug with Swift Playgrounds. I tried it in a Sample Project in Xcode and it worked just fine. I you experience this only in Swift Playgrounds and only on iPad you could file a bug report here: https://feedbackassistant.apple.com
Take care,
David
Hi,
A WidgetURL will always open the app when tapped. There is no way around that. Maybe they will add this functionality later.
Hi,
when you want to add rounded elements to a widget you should use ContainerRelativeShape(). This will adjust the corner radius depending on its parent.
VStack{
}
.background(ContainerRelativeShape())
Take care,
David
The same thing is now happening with the current Xcode Version and the M1 MacBook Pro. I had to install the 12.5 beta to get it running reliably again...
Hi,
NavigationViews are, depending on device and orientation, displayed in a few different ways. To achieve what you want you need to modify the NavigationView using:
NavigationView{
Text("View")
}.navigationViewStyle(StackNavigationViewStyle())
Take care,
David
Hi,
Widgets will always launch the app when they are tapped, so there is no way to only add an action to the widget. Depending on the Widget Size you have the option of using Tap targets. The small Widget only has one big button, itself. The large Widget has a few targets that can perform different actions by using different URLs, but they also launch the app.
Take care,
David