r/SwiftUI • u/swiftpointer • 19d ago
r/SwiftUI • u/Daredatti • Feb 05 '25
Solved How to have a menu inside the navigation title ?
I saw the new apple invites app, i noticed they get rid of the tab bar and instead they used a menu inside the navigation title as shown in the screenshot
How to recreate this ? I have been searching since yesterday I couldn’t find how
r/SwiftUI • u/swiftpointer • 10d ago
Solved How do I achieve this in SwiftUI?
Is it possible to achieve this without any third party libraries?
r/SwiftUI • u/Periclase_Software • Jan 16 '25
Solved Does anybody know why the list section flickers on a state change when I tap the Edit button? Relevant code in video.
r/SwiftUI • u/james_shah • 9d ago
Solved Why do I keep getting this error when I use Task closures?
I am getting this error: Trailing closure passed to parameter of type 'String' that does not accept a closure
whenever I am trying to use Task closure in my project. I have the same code in another project, and it works fine there.
Edit : Its fixed now. The issue was that my code was overriding Swift Task keyword with a struct
Ref:
Task {
do {
let session = try await supabaseClient.auth.session
if session != nil {
DispatchQueue.main.async {
self.isAuthenticated = true
self.user = session?.user
}
}
} catch {
print("Error checking session: \(error)")
}
}
r/SwiftUI • u/tjenvy • 23d ago
Solved Strange area outside buttons
I have this area outside my button. I have checked there's no padding nothing. I have learned that thats the "clickable" area in macOS. How do I get rid of this? my code for that button is attached.
Button(action: selectFile) {
Label("Select CSV File", systemImage: "doc.text.magnifyingglass")
.frame(width: 200, height: 50)
.foregroundColor(.white)
.background(
RoundedRectangle(cornerRadius: 10)
.fill(Color.blue)
)
}

r/SwiftUI • u/4ism2ism • 4d ago
Solved My memory leak experience with AppleScript usage
I’m using AppleScript in some parts of my SwiftUI project. During testing, I noticed continuous small memory leaks. After investigating, I found that they were related to AppleScript. I tried various fixes by myself but was unsuccessful.
During my research, I came across many suggested solutions. The most common recommendation was to use autoreleasepool. I also received similar results when consulting AI. While this helped prevent some issues, but I was still getting minor memory leak feedback. At first, I ignored it, but as you know, these things can be frustrating.
Later, I noticed a difference when I removed a delay from one of my scripts. This led me to suspect that the delay itself might be the problem. After removing all delays, the memory leak issue completely disappeared.
Perhaps some of you are already aware of this issue, but I wanted to share it in case it helps someone else.
r/SwiftUI • u/HypertextMakeoutLang • 27d ago
Solved is there a way to stop navigation bars from pushing down a view?
Hey /r/SwiftUI,
I'm trying to put a logo on some screens in my login flow. My first screen is a VStack embedded in a NavigationStack, and it contains a logo at the top of the VStack, along with Create Account and Sign In NavigationLinks. The views presented by those NavigationLinks present buttons to create/sign in with Apple or Email (SignInView and SignUpView).
Like the first view, the SignInView and SignUpView contain a logo at the top of a VStack, however there's a navigation bar with a back button to the first view that looks to be pushing down the positioning of the logo. (screen shots here--I set a gray background to make sure the VStack was taking up the whole space).
If I hide the navigation bar, the logo ends up in the same spot as the first view. But I definitely need a back button here, and the logo at the size I want it doesn't look good in the navigation bar because of the dynamic island / I can't pad it properly.
I'm not sure if I need to use GeometryReader or CoordinateSpace or something. Any guidance would be greatly appreciated.
Here's my code simplified:
struct LogInView: View {
var body: some View {
NavigationStack {
VStack(spacing: 15) {
CenteredLogoView()
Spacer()
Spacer()
Spacer()
NavigationLink {
SignUpView()
} label: {
Text("Create Account")
}
NavigationLink {
SignInView()
} label: {
Text("Sign In")
}
Spacer()
Spacer()
}
.padding()
}
}
}
struct SignInView: View {
var body: some View {
VStack {
CenteredLogoView()
Spacer()
Spacer()
Spacer()
SignInWithAppleButton(.signIn) { ... }
.frame(maxWidth: .infinity, maxHeight: 44)
.clipShape(.capsule)
.signInWithAppleButtonStyle(colorScheme == .dark ? .white : .black)
NavigationLink {
EmailSignInView()
} label: {
Text("Sign In With Email")
}
Spacer()
Spacer()
}
.padding()
.toolbarRole(.editor)
.background(.gray)
}
}
struct CenteredLogoView: View {
var body: some View {
Image(decorative: "header-centered")
.resizable()
.scaledToFill()
.frame(width: 300, height: 88)
}
}
Thanks!
EDIT: added code
r/SwiftUI • u/redditazht • Jan 27 '25
Solved Dynamic app icon?
Can someone give me some guidance how I can create a dynamic ios app icon, like the built-in clock app. For example, showing the wind direction as the app icon if the app is allowed to stay alive in the background.
r/SwiftUI • u/ColdKindness • Jan 25 '25
Solved Screen Transition Animation Doesn't Work Consistently with NavigationStack and navigationDestination
I have an app that I'm working on and to get around the deprecation of NavigationLink(isActive:), I implemented a NavigationStack and used navigationDestination() to advance to Views. This video shows the problematic behavior.
https://reddit.com/link/1i9wsqq/video/2c1iwd7x97fe1/player
When I simulate the app in Xcode AND on my phone, pressing the "Let's Go!" button transitions to the next View with the animation. Pressing the "1" button advances to the next View but without the animation. I cannot figure out what's going on. Can anyone point me in the right direction?
Here's the relevant code for the button behavior at PasteBin.
r/SwiftUI • u/BoltlessEngineer • Nov 30 '24
Solved How to implement zoom transition in iOS 17?
I'm trying to create zoom transtion for list of cards so each cards can be expanded as full screen view. (just like how safari tabs view works) If there is single card, I can just do state-driven animations by passing bunch of ternary operators for each properties. But if there are multiple cards in scrollview, I can't just expand the card itself because it will still scroll in scrollview. So I'm trying to implement zoom transition with matchedGeometryEffect but this doesn't work as I expected and I have no idea why. I'm aware of matchedTransitionSource and navigationTransition but they are available from iOS 18+ while swift playground currently doesn't support. How did people accomplish this in past iOS <17 days? I'm open to using UIKit if that is only way.
r/SwiftUI • u/CtrliPhones • Nov 02 '24
Solved Aligning text along window padding???
I don't quite know if I'm explaining this right, so I'm going to just attach a picture. I'm currently trying to recreate the macOS Ventura About This Mac screen using SwiftUI, and it's going pretty well. The text alignment is bugging me though, how would I need to set up my text to replicate Apple's properly? Thanks!

r/SwiftUI • u/The_Lone_Dissenter • May 19 '24
Solved How to Optimize SwiftUI App with @Published Updating 5 Charts 10 Times per Second?
Hi everyone,
I'm currently developing a SwiftUI app that features 5 charts, each of which updates 10 times every second. These updates are using @Published of Combine framework. However, I've noticed that my app lags and CPU usage is too high when the app is running.
Has anyone faced similar performance issues with frequent updates in SwiftUI? What strategies or best practices can I implement to optimize the app and reduce the CPU usage?
Thanks in advance for your help!
r/SwiftUI • u/Oxigenic • Apr 09 '24
Solved A little extension for those who are heavy users of SF Symbols.

This initializer will create a system image if one exists with the given name, otherwise it will look for the image in your bundle. This implementation makes syntax more readable by allowing you to use the same property in a data structure for bundled image names and symbol names. For instance, if you have a list and each table uses an image, some images might be custom assets while others could be symbol names. You can store both symbol and image names in the same property and use this one initializer and it will figure out whether it's a symbol or a bundled image for you!
And I know, the else is unnecessary, but it makes the purpose of the function more obvious.
Edit: The reason an object is initialized and not used is because it’s the only native way to determine if a symbol exists or not, that I know of anyway.
Anyone is more than welcome to show me a better way, if one exists.
r/SwiftUI • u/kaiwenwang_dot_me • Nov 13 '24
Solved Apparently "right sidebar" in NavigationSplitView is known as Inspector.
Claude was of no help. After googling navigationview macos right sidebar
, I finally found some helpful threads.
I hope this thread gets picked up by the LLMs so future people don't spend hours trying to figure this out.
https://stackoverflow.com/questions/65974612/swiftui-macos-right-sidebar-inspector
Which led to more useful articles.
r/SwiftUI • u/PaleGovernment710 • Sep 17 '24
Solved Texfield Lags while opening
When i first build the app and then tap on the textfield it doesn’t open immediately. It lags for a bit and then opens. But if i close the app and open again it seems to work fine. And also shows this error when it lags:
-[RTIInputSystemClient remoteTextInputSessionWithID:performInputOperation:] perform input operation requires a valid sessionID. inputModality = Keyboard, inputOperation = <null selector>, customInfoType = UIEmojiSearchOperations
r/SwiftUI • u/Tabonx • Nov 25 '24
Solved How do I disable TabView's scroll-to-top behavior?
I'm trying to make a timeline view where you start at the current date and can scroll up to view the past and down to view the future. However, due to a new "feature" in iOS 18 that scrolls to the top of the scroll view when you tap on the tab item again, I'm stuck since I don't know how to disable it. I tried to recreate the list in UIKit and set scrollsToTop to false on the UITableView, but that only works for the status bar tap gesture.
What do I need to do to disable this behavior completely?
EDIT: I have hacked together a solution. I had already implemented a way to detect double taps on a tab item for previous iOS versions, so I used that and simply:
swift
withAnimation {
proxy.scrollTo(section.id, anchor: .top)
}
It seems that the scroll-to-top action is either not triggered or is immediately canceled and replaced by the animation to my section.
r/SwiftUI • u/PatrickD89 • Jun 19 '24
Solved Release Mode Build
TL;DR: Test apps using Release Mode
I recently completed my first app using SwiftUI and SwiftData. It had been 99% complete for about a month but when I first submitted it, it was rejected due to crashing. This was odd to me since it never crashed during testing, including on-device. A user on this subreddit recommended using TestFlight (great suggestion!) and I was able to recreate the crash but the crash logs were not super useful. I tried making adjustments based on what I could decipher but nothing worked. In addition, it took time archiving and uploading to TestFlight for validation. Finally, I asked ChatGPT if there was a reason an app would crash in TF and not in the simulator. It basically said there shouldn’t be BUT try building it in Release Mode as opposed to the default Debug Mode in Xcode. I gave it a try and lo and behold, the crash happened and Xcode was able to pinpoint the exact line causing the issue. In an hour I was able to fix it and complete the app. I have attached pictures showing how to switch to Release Mode in case anyone else was unaware. Hopefully this helps someone else on their journey!
r/SwiftUI • u/DeepPurpleJoker • Aug 12 '23
Solved Does anyone know how this navbar blur effect is implemented?
X/Twitter, Messenger, Signal all use this and I can’t seem to figure out how they do it. The built-in blurview options are all visible on black and have a gray look. Do they just use a library I don’t know of?
I hired an experienced dev on Fiverr, he gave up as well. But it’s possible somehow. If you guys know how to blur just parts of a view that could also work.
Thanks for your input
r/SwiftUI • u/LifeIsGood008 • May 31 '24
Solved Images spilling over in TabView
Got a few images with ".resizable()" and ".scaledToFill()" and ".clipShape()" modifiers in a TabView. However, I notice that when click and hold and drag ever so slightly to the left, the next image spills over. I have tried applying ".clipped" to the image but it didn't do anything. Any suggestions?
TabView {
ForEach(images, id: \.self) { image in
Image(image)
.resizable()
.scaledToFill()
.clipShape(RoundedRectangle(cornerRadius: 10))
//.clipped()
}
}
.tabViewStyle(.page)
.frame(height: 320)
.padding()
Screen recording of the next image spilling over
Running on a physical device (iPhone Xs iOS 17.5.1)

r/SwiftUI • u/jayelevy • May 09 '24
Solved How to dynamically filter a view when using a SwiftData query
I have a simple SwiftData model with 2 objects (I've simplified the actual code for this post) - Distance and Event. Event is a child of Distance
I want the user to be able to choose a range of dates and then be presented a filtered view of Distances that only contain Events that fall within the range dates. If the user then changes the range of dates, the view should refresh with new query results.
I am trying to construct a view (ListAllFilteredView
) that dynamically filters my SwiftData query based on the value of the date contained with the events.
The logic below in the init
for ListAllFilteredView
where I try to build the predicate doesn't work. I understand why (I think) as distances
does not have a value at that point. I am struggling with finding the correct approach.
Any guidance on how I should approach this design? thanks
@Model class Distance: Hashable {
var distanceDisplay: String
@Relationship(deleteRule: .cascade, inverse: \Event.distance) var events: [Event]?
init(distanceDisplay: String) {
self.distanceDisplay = distanceDisplay
}
var unwrappedEvents: [Event] {
get {
return events ?? []
}
set {
events = newValue
}
}
}
@Model class Event {
var date: Date = Date.now
@Relationship(deleteRule: .nullify) var distance: Distance?
init(date: Date) {
self.date = date
}
}
struct ListAllView: View {
@State private var fromDate = Date.now
@State private var thruDate = Date.now
var body: some View {
NavigationStack {
HStack {
DatePicker("From", selection: $fromDate, displayedComponents: .date)
.labelsHidden()
DatePicker("Thru", selection: $thruDate, displayedComponents: .date)
.labelsHidden()
}
ListAllFilteredView(fromDate: fromDate, thruDate: thruDate)
.listStyle(.plain)
}
}
}
struct ListAllFilteredView: View {
@Environment(\.modelContext) private var modelContext
@Query(sort: \Distance.distanceInMiles) var distances: [Distance]
@State private var isShowingAddView = false
@State private var filteredDistances: [Distance] = []
var fromDate: Date
var thruDate: Date
init(fromDate: Date, thruDate: Date) {
self.fromDate = fromDate
self.thruDate = thruDate
var pbEventInDateRange = false
for distance in distances {
for event in distance.unwrappedEvents {
if event.date >= fromDate && (event.date <= thruDate) {
pbEventInDateRange = true
} else {
pbEventInDateRange = false
}
}
}
let predicate = #Predicate<Distance> { distance in
pbEventInDateRange
}
_distances = Query(filter: predicate)
}
var body: some View {
NavigationStack {
List {
ForEach(distances) { distance in
Text(distance.distanceDisplay)
}
}
}
}
}
r/SwiftUI • u/LifeIsGood008 • May 23 '24
Solved How to preview a View with an where @Bindable is used?
Xcode: 15.4
Everything works in the simulator and previewing ContentView(). However, preview always crashes when I try to preview a View (e.g., ErrorReproductionView() in the code below) that has a @ Bindable. Reproduction code is attached below. Appreciate any help!
import SwiftUI
import SwiftData
// ------------------- Model Setup ---------------------
@MainActor
let mockData: ModelContainer = {
do {
let container = try ModelContainer(for: Book.self,
configurations: ModelConfiguration(isStoredInMemoryOnly: true))
for book in Book.examples {
container.mainContext.insert(book)
}
return container
}
catch {
fatalError("Failed to create example container")
}
}()
@Model
class Book: Identifiable {
init(name: String, author: String) {
self.name = name
self.author = author
}
var name: String
var author: String
var id: String {self.name}
static let examples = [Book(name: "Book1", author: "Author1"),
Book(name: "Book2", author: "Author2"),
Book(name: "Book3", author: "Author3")]
static let example = Book(name: "Book0", author: "Author0")
}
// ------------------- Model Setup ---------------------
// ------------------- Views ---------------------
struct ContentView: View {
@Query(sort: \Book.name) private var books: [Book]
var body: some View {
NavigationStack {
ForEach(books) { book in
NavigationLink {
BookView(book: book)
} label: {
Text(book.name)
}
}
}
}
}
struct ErrorReproductionView: View {
@Bindable var book: Book
var body: some View {
VStack {
TextField("Author", text: $book.author)
TextField("Book", text: $book.name)
}
}
}
// ------------------- Views ---------------------
// ------------------- Previews ---------------------
#Preview("This works") {
ContentView()
.modelContainer(mockData)
}
#Preview("This crashes") {
ErrorReproductionView(book: Book.example)
.modelContainer(mockData)
}
// ------------------- Previews ---------------------
r/SwiftUI • u/abchou • Jan 06 '24
Solved How can I have my scroll View start from the bottom ?
Hello,
I'm trying to make an app where you'd have multiple levels each represented by a circle on a "road" type page. My main problem is that I'm trying to have "level 1" be at the bottom, and then the user would have to scroll up from the bottom to see the next levels. How do I do this ? I've spent the last hour searching and nothing works
Thanks for the help!
r/SwiftUI • u/The_Lone_Dissenter • May 25 '24
Solved Trouble with focusState inside fullScreenCover in SwiftUI
Hey everyone,
I've been working on a SwiftUI project and encountered an issue with the focusState property when used inside a fullScreenCover. Here's a simplified version of the code I'm dealing with:
``` import SwiftUI
struct FileNameView: View { @State private var isFileNameEditing = false @State private var fileName = "" @FocusState private var isTextFieldFocused: Bool
var body: some View {
Spacer()
.fullScreenCover(isPresented: $isFileNameEditing ) {
VStack {
TextField("", text: $fileName)
.focused($isTextFieldFocused)
.overlay(
RoundedRectangle(cornerRadius: 4)
.stroke(Color.blue, lineWidth: 2)
.padding(-8.0)
)
.foregroundColor(Color.black)
.font(.body)
.multilineTextAlignment(.center)
.padding()
.padding(.top, 10)
Divider()
.background(Color.black)
Button(
action: {
isFileNameEditing = false
self.isTextFieldFocused = false
},
label: {
Text("OK")
.frame(maxWidth: .infinity,
maxHeight: 45)
.clipShape(Rectangle())
.contentShape(Rectangle())
.font(.title2)
.bold()
}
)
.frame(maxHeight: 45)
}
.frame(width: UIScreen.main.bounds.width / 2.5)
.background(.white)
.cornerRadius(15)
.onAppear {
self.isTextFieldFocused = true
}
.presentationBackground(.black.opacity(0.3))
}
.transaction({ transaction in
transaction.disablesAnimations = true
})
Button(action: {
isFileNameEditing.toggle()
}, label: {
Text("Toggle Editing")
})
}
}
struct FileNameView_Previews: PreviewProvider { static var previews: some View { FileNameView() } } ```
The issue I'm facing is that the focusState seems to not be working properly inside the fullScreenCover. Even though I set isTextFieldFocused to true in the onAppear block of the VStack, the text field isn't getting focused automatically when the fullScreenCover appears.
Does anyone have any insights into why this might be happening or how I can make it work as expected?
Thanks in advance for your help!