Hello,
I have a view has 4 textfields and a button.
I want to show 4 values from textfields on popup messagebox. so I wrote a following codes.
@State private var lender = ""
@State private var amount = ""
@State private var rate = ""
@State private var duration = ""
Button(action: {showingAlert = true},
label: {
Text("Inputs")
.padding()
.background(RoundedRectangle(cornerRadius: 10).strokeBorder())
}).padding(10)
.accentColor(.green)
.alert("Inputs", isPresented: $showingAlert){
Text("Lender: \(lender)").font(.title3)
Text("Amount:\(amount)").font(.title3)
Text("Rate:\(rate)")
Text("Duration:\(duration)")
Button("OK", role: .cancel){}
}
When I run this code, Alert popped up but there's no values.
If someone point my mistakes, I'd very appreciated.
thanks,
c00012
SwiftUI
RSS for tagProvide views, controls, and layout structures for declaring your app's user interface using SwiftUI.
Posts under SwiftUI tag
200 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
When I try to change the arrow direction for SwiftUI popover it's not working at all, but in UIKit it seems to be ok
Please check the sample code
Button {
showPopover.toggle()
} label: {
Text("Show Popover")
.padding(60)
.border(Color.yellow)
}
.popover(
isPresented: $showPopover,
arrowEdge: .bottom // issue here
) {
Text("Popover conent")
}
When you try to present medium height popover from the bottom of iPhone view then popover is clipped in iOS18 but works in old devices
Sample code
Button("Show Popover") {
showPopover.toggle()
}
.popover(
isPresented: $showPopover,
arrowDirection: arrowDirection
) {
conent
}
Result
Context menu on tvOS LazyVGrid selecting wrong item.
It works fine if selecting items on last row.
Testing on code from https://developer.apple.com/videos/play/wwdc2024/10207/
I just added contextMenu
LazyVGrid(columns: columns, spacing: 40) {
ForEach(sortedMatchingAssets) { asset in
Button {} label: {
asset.landscapeImage
.resizable()
.aspectRatio(16 / 9, contentMode: .fit)
.contextMenu {
Button("Test") {}
}
Text(asset.title)
}
.buttonStyle(.borderless)
}
}
Attached video with the bug - https://www.icloud.com/iclouddrive/020zq2PxZ_E_1Pr0vE86-8aww#Screen_Recording_2024-06-13_at_9.26.15%E2%80%AFPM
How are SwiftUI Shapes supposed to work with Swift 6?
Shape conforms to View which uses @MainActor but the path function and animatableData are both nonisolated. How can they access animatable properties that have to be a var on the main actor?
Below is a simple Shape that will show these warnings:
struct SimpleShape: Shape {
var width: Double
var animatableData: Double {
get { width }
set { width = newValue }
}
func path(in rect: CGRect) -> Path {
var path = Path()
let width = self.width
path.addRect(.init(origin: rect.origin, size: .init(width: width, height: rect.height)))
return path
}
}
I am attempting to make a macOS app to show a large popup with no titlebar and a transparent background that spans the entire active display.
Currently, I am attempting the last part, with the sizing. I used an example on the relevant developer documentation page. This is the code I am using in my App struct:
@main
struct MakeGoodChoicesApp: App {
...
var body: some Scene {
...
Window("Make Good Choices", id:"popup") {
PopupWindowContentView()
.ignoresSafeArea(.all)
}
.windowIdealPlacement {_, context in
return WindowPlacement(
x: context.defaultDisplay.bounds.minX,
y: context.defaultDisplay.bounds.minY,
width: context.defaultDisplay.bounds.width,
height: context.defaultDisplay.bounds.height
)
}
}
}
When running my application and using some code to open the popup window, I get the following result:
I would expect the window to expand past the safe area, but it seems as if macOS clamped the window's size down to inside the safe areas.
I would appreciate any help, many thanks!
Hi all,
I am new to Swift and I have found an issue which I can't fix.
I use a TabView and if I change the views a few times, and go back to this view I get this error and I can't tab on any of the views any longer in the Navigation Stack.
The way to fix it, is to force close the app and reopen it.
Error message:
"A NavigationLink is presenting a value of type “NavigationItem” but there is no matching navigationDestination declaration visible from the location of the link. The link cannot be activated.
Note: Links search for destinations in any surrounding NavigationStack, then within the same column of a NavigationSplitView."
Code:
struct ToolsMainView: View {
@State private var navigationPath = NavigationPath()
var body: some View {
NavigationStack(path: $navigationPath) {
VStack {
ScrollView(showsIndicators: false) {
VStack {
ForEach(navigationItems) { item in
NavigationLink(value: item) {
HStack(alignment: .center, spacing: 12) {
Image(systemName: item.icon)
Text(item.title)
Spacer()
Image(systemName: "chevron.right")
}
}
}
}
.scrollTargetLayout()
}
.scrollTargetBehavior(.paging)
}
.navigationDestination(for: NavigationItem.self) { item in
viewMenuItems(item)
}
}
.scrollContentBackground(.hidden)
}
func viewMenuItems(_ tool: NavigationItem) -> some View {
switch tool.menu {
case .forms:
return AnyView(View1())
case .stage:
return AnyView(View2())
case .margin:
return AnyView(View3())
case .vat:
return AnyView(View4())
case .tvheight:
return AnyView(View5))
case .tvsize:
return AnyView(View6())
case .cable:
return AnyView(View7())
case .project:
return AnyView(View8())
case .tasks:
return AnyView(View8())
}
}
}
Do you have any suggestions?
Thank you
Hi
How can we add multi view to NavigationPath in one go like in code below maybe using something like path.append(mobiles.all) ? where all 3 views of mobiles Array get added at once ?
Kindest Regards
`struct NavigationPathView: View {
var mobiles: [Mobiles] = [.init (name: "iPhone", imageName: "folder", color: .mint),
.init (name: "Samsung", imageName: "pin", color: .pink),
.init (name: "Mac Pro", imageName: "book", color: .gray)]
@State var path = NavigationPath()
var body: some View {
NavigationStack (path: $path) {
List {
Section ("Platforms") {
Button("Go To Platform") {
path.append(mobiles.first!)
}
Button("Go To Mobile") {
path.append(mobiles.last!)
}
Button("Add All Mobiles") {
}
}
}
}
.navigationDestination(for: Mobiles.self) {mobile in
ZStack {
mobile.color.ignoresSafeArea()
VStack {
Image(systemName: mobile.imageName)
Label (mobile.name, systemImage: mobile.imageName)
.font(.largeTitle).bold().foregroundColor(.white)
Button("Go Home") {
path.removeLast(path.count)
}
}
}
}
}
}
I have a List in a NavigationStack and the list items have swipeActions
struct ListItem: Identifiable {
var id: String { return name }
let name: String
}
struct ContentView: View {
@Environment(\.editMode) var editMode
@State var listItems = [
ListItem(name: "Cow"),
ListItem(name: "Duck"),
ListItem(name: "Chicken")
]
var body: some View {
NavigationStack {
List(listItems) { listItem in
NavigationLink {
Text(listItem.name)
} label: {
Text(listItem.name)
}
.swipeActions(edge: .trailing) {
Button(action: { }, label: { Text("Edit") }).tint(.blue)
Button(role: .destructive, action: {}, label: { Text("Delete") })
}
}
.navigationTitle("Animals")
.navigationBarItems(trailing: EditButton())
}
}
}
For users who might have problems with the swipe gesture, I would like to have the Swipe Actions display when the list is in editMode.
Is there a programmatic way to show the swipeActions?
I have also tried using ForEach with an onDelete modifier. Then if you hit the edit button, it shows a circular button on the left for each row. If you click the circular button then it will show the swipe actions but I don't want the extra step of pressing the circular button.
For the past couple of years, Apple has been using custom sliders in Music, Podcasts, and on the Lock Screen for scrubbing music and controlling volume.
But those sliders are not available to 3rd party devs. We can recreate them theoretically for scrubbing audio. But not for volume, where in UIKit we are supposed to use MPVolumeView.
Anyone from Apple? Are there any plans to make the slider styles used in Apple's audio apps available to the rest of us?
FB12261162
In the first Xcode 16 beta, none of my SwiftUI previews work - they all just crash on start up.
Has anybody run into this and found a workaround? Have tried all the usual steps of cleaning the project/restarting Xcode.
In SwiftUI we can use @AppStorage to save app settings. In my app, I have a settings view which allows the user to change various settings. Since there are many of them, it's not practical to declare a binding for each setting between the settings view and whatever other views effectively use that setting.
Is there a more convenient way to store a setting in one view and access it in another view?
Hi,
I'm having some trouble when animating my chart with a custom AxisValueLabel. Specifically, as soon as I set its init parameter centered to true, the x axis' leftmost value of the previous dataset sticks around during the animation to the next dataset.
Here's a GIF of a screen recording from a minimum reproducible example I built. Keep a close eye on the x axis of the third BarMark, and notice how the 0 from the first BarMark sticks around longer than necessary / intended. While it isn't visible in the GIF, the extra 0 eventually does disappear, but only after the transition if fully complete, making the animation feel distracting and amateur-ish, rather than smooth.
This is my code for the x axis. If I turn centered to false, this problem immediately goes away.
.chartXAxis {
AxisMarks(
preset: .aligned,
values: .stride(
by: .day,
count: 1,
calendar: .current
)
) { value in
AxisValueLabel(centered: true) {
Text("\(value.index)")
}
}
}
As you might be able to tell, my x axis is date based, and I'm working on showing one BarMark per day of the week.
I have a ZIP of my minimum reproducible example that I can provide for anyone interested, although I don't know how to share it here.
Any advice on what I can do to fix this?
Hi,
I am having trouble changing from deprecated NavigationView to NavigationStack.
I have looked through the article, and a number of examples and tutorials - they all show examples where the user clicks on a choice or a button in the view. But in my case, the navigation is programmatic based on changes to a value. I have below the old code, and my attempt at new revised code ( needs to run on IOS16, and cannot use API introduced in IOS 17). The new code compiles fine, but the screen does not navigate to new views as the value changes. I debug print the value as it changes, and the value for 'detailView' does change. The old code works without a problem - just that I get a warning that I am using deprecated APIs.
The old code:
struct MainView: View {
@EnvironmentObject var gameVm: GameViewModel
var body: some View {
NavigationView {
VStack {
NavigationLink(destination: PlayView().transition(.slide),
tag: .playView, selection: $gameVm.detailView) {
EmptyView()
}
NavigationLink(destination: GamePausedView().transition(.scale),
tag: .gamePausedView, selection: $gameVm.detailView) {
EmptyView()
}
NavigationLink(destination: SettingsView().transition(.slide),
tag: .settingsView, selection: $gameVm.detailView) {
EmptyView()
}
IdleView().transition(.slide)
}
}
.navigationViewStyle(.stack)
}
}
My attempt at the revised code:
struct GameMainView: View {
@EnvironmentObject var gameVm: GameViewModel
@State private var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
VStack {
NavigationLink(value: DetailView.playView) {
EmptyView()
}
NavigationLink(value: DetailView.gamePausedView) {
EmptyView()
}
NavigationLink(value: DetailView.settingsView) {
EmptyView()
}
IdleView().transition(.slide)
}
}
.navigationDestination(for: DetailView.self) { dtlViewType in
if dtlViewType == .playView {
PlayView().transition(.slide)
} else if dtlViewType == .settingsView {
SettingsView().transition(.slide)
} else if dtlViewType == .gamePausedView {
GamePausedView().transition(.slide)
}
}
}
}
What am I doing wrong? Thanks in advance for any help.
I saw onnoffitacation in the Behavior configuration of Reality Composer pro, which asked me to enter the Nofficatition name, that is to say, this requires swift in Xcode to send a message. There is a message name in the message, so I hope you can write an list for me how to use Swift in Xcode to send a message containing the message name.
I'm trying to use
@Environment(\.openDocument) private var openDocument
but it seems to only be available on macOS.
How can I open a document programmatically on iOS? My app has a custom interface for browsing and opening files, so that a tapped file should be shown in the current window, replacing the current file if it exists.
Hi using this new Text method for timers is not counting down. Here is an example of how I implemented it.
Text(.now, format:.timer(countingDownIn: Date.now..<Date.now.addingTimeInterval(120),
showsHours: true,
maxFieldCount: 2,
maxPrecision: .seconds(60))
)
After waiting over a minute it never counts down
Apple revealed the ContactsAccessButton in the WWDC24 session 10121: Meet the Contact Access Button.
After watching the video, reading through the
documentation as well as the
sample code
, I can only find a SwiftUI ContactsAccessButton.
However, our code base is written largely in UIKit, and our team prefers to do complex work and customization with lists via UITableView as opposed to SwiftUI List. So we would greatly prefer to use a UIKit ContactAccessButton.
Is there not a UIKit equivalent to ContactsAccessButton? If there is, where can we find it?
Hey Guys, a have some problens with Xcode preview for some reason I'm getting this error
LinkDylibError: Failed to build CardDetailsScreen.swift
Linking failed: linker command failed with exit code 1 (use -v to see invocation)
ld: -make_mergeable can only be used when creating a dynamic library
clang: error: linker command failed with exit code 1 (use -v to see invocation)
previews_diagnostics_summary.txt
Hello,
When I run the following view on my iPhone with VoiceOver enabled, I encounter an issue with the voiceover cursor when I perform the following steps:
Move the VoiceOver cursor to the tabview dots for paging.
Swipe up with one finger to go to the next tab.
--> Tabview moves to the next tab.
--> The VoiceOver cursor jumps up to the tab.
But instead of the actual tab the previous tab is shown in the tabview again.
You can also see that the border of the VoiceOver cursor extends into the previous tab.
I suspect it has to do with the fact that despite the clipped modifier, the size of the image remains the same and extends into the previous tab.
struct ContentView: View {
var body: some View {
VStack {
TabView {
ForEach(1..<6) { index in
Button(
action: { },
label: {
ZStack {
GeometryReader { geo in
Image(systemName: "\(index).circle")
.resizable()
.scaledToFill()
.frame(width: geo.size.width)
.clipped()
}
}
}
)
.buttonStyle(PlainButtonStyle())
.padding([.bottom], 50)
}
}
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
}
.padding()
}
}
How can I fix this?
Best regards
Pawel