Visually it looks right, but functionally it doesn't work. If I tap on any time, it seems to open up ArticleDetailView for every article - so 6 or more views open simultaneously. Can you fix that?
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
@State private var selectedArticleSlug: String? // State variable to track selected article for navigation
code
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
var body: some View {
NavigationStack {
List {
VStack {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
// Display the featured article if available
if let featuredArticle = vm.articles.first {
Section {
FeaturedArticleRow(article: featuredArticle)
}
}
// Display the rest of the articles
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.task {
await vm.load() // Load articles when the view appears
}
.navigationDestination(for: String.self) { slug in
ArticleDetailView(slug: slug) // Navigate to ArticleDetailView when an article is selected
}
}
.listStyle(PlainListStyle())
}
}
}
struct LatestListViewTest_Previews: PreviewProvider {
static var previews: some View {
LatestListViewTest()
}
}
Assistant
The issue is that you have two different navigation mechanisms mixed:
You use direct NavigationLink inside the ForEach for each article.
You also have a .navigationDestination(for: String.self) modifier that listens for navigation triggered by selectedArticleSlug.
But you never actually set selectedArticleSlug anywhere, so the .navigationDestination is not used properly.
Because you have NavigationLinks inside the list, tapping any article triggers multiple navigation links simultaneously (likely because of the way the list and navigation stack interact).
How to fix it:
You should choose one navigation approach:
Use only NavigationLinks inside the list (simpler).
Or use programmatic navigation with selectedArticleSlug and .navigationDestination.
Fix using only NavigationLinks (simplest):
Remove the selectedArticleSlug state and .navigationDestination modifier entirely, and keep the NavigationLinks inside the ForEach.
swift
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
List {
VStack {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
// Display the featured article if available
if let featuredArticle = vm.articles.first {
Section {
FeaturedArticleRow(article: featuredArticle)
}
}
// Display the rest of the articles
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.task {
await vm.load()
}
}
.listStyle(PlainListStyle())
}
}
}
User
That nearly works. The ArticleRows all display correctly and link correctly. However, the FeatureArticleRow does not link to an article. Can you fix that?
Assistant
Got it! The issue is that your featured article is inside a Section but wrapped in a Button (or NavigationLink), and sometimes Section can interfere with tappable areas or styling.
To fix the featured article navigation:
Wrap the featured article row in a NavigationLink just like the other articles.
Avoid wrapping it inside a Section unless you want a section header or footer.
If you want to keep the section, put the NavigationLink inside the section.
Here’s the fixed version using NavigationLink for the featured article:
swift
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
List {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
// Featured article as a NavigationLink
if let featuredArticle = vm.articles.first {
Section {
NavigationLink(destination: ArticleDetailView(slug: featuredArticle.slug)) {
FeaturedArticleRow(article: featuredArticle)
}
}
}
// Other articles
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.listStyle(PlainListStyle())
.task {
await vm.load()
}
}
}
}
Explanation:
The featured article is now wrapped in a NavigationLink inside the Section.
This makes the entire featured article row tappable and navigates correctly.
The rest of the articles remain unchanged.
If you want to use programmatic navigation instead (with selectedArticleSlug), just replace the featured article’s Button with a NavigationLink or a Button that sets the slug, but the above is the simplest fix.
Let me know if you want me to provide the programmatic navigation version with the featured article fixed!
User
One step forward, one step back. Now the FeatureArticleRow links, but it has introduced an ugly vertical line and chevron to the right of it. Keep the link but make the line and chevron go away.
Assistant
Great, you want the featured article to be tappable (NavigationLink) but without the default List row styling — i.e., no vertical line, no chevron.
By default, NavigationLink inside a List shows the disclosure indicator (chevron) and the separator line.
How to remove the chevron and separator line but keep the tappable behavior?
Approach:
Use .buttonStyle(PlainButtonStyle()) on the NavigationLink to remove the button styling (including the chevron).
Use .listRowSeparator(.hidden) on the row to hide the separator line.
Optionally, use .listRowBackground(Color.clear) to remove any background color.
Updated code snippet for the featured article:
swift
Section {
NavigationLink(destination: ArticleDetailView(slug: featuredArticle.slug)) {
FeaturedArticleRow(article: featuredArticle)
}
.buttonStyle(PlainButtonStyle()) // Remove chevron and button style
.listRowSeparator(.hidden) // Hide separator line
.listRowBackground(Color.clear) // Optional: remove background color
}
Full example with context:
swift
User
Closer. That removed the chevron, but the vertical line is still there. Make that go away.
Assistant
Ah, the vertical line you’re seeing is the list row inset separator line or the default list row background that looks like a vertical line on the left side in grouped or plain list styles.
To remove that vertical line, you need to:
Remove the row insets so the row content stretches edge-to-edge.
Hide the separator line.
Possibly set the list style or row background to avoid the default inset styling.
Here’s how to fix it:
Add .listRowInsets(EdgeInsets()) to the featured article’s NavigationLink to remove the default padding/insets, which removes the vertical line.
Thanks for the update! The persistent vertical line is likely the list row background or the default inset styling that SwiftUI applies in List with PlainListStyle().
To completely remove that vertical line, try this:
Use .listRowInsets(EdgeInsets()) to remove insets (you did that).
Also set .listRowBackground to Color.clear or a custom background.
Wrap the featured article row in a ZStack or background modifier to override the default background.
Make sure the List style is .plain or .insetGrouped depending on your needs.
If the vertical line is still there, it might be the list separator inset or the list row background.
A more aggressive approach:
Try removing the section entirely for the featured article and place the featured article as a standalone row at the top of the list, with no section, and apply these modifiers:
Can you think of something completely different to try?
Assistant
Thanks for your patience! Since the usual .listRowInsets(EdgeInsets()) and .listRowSeparator(.hidden) aren’t removing the vertical line, it’s likely caused by the default list row background or the list style itself.
Completely different approach: Don’t use List for the featured article row
Instead, place the featured article above the List as a separate view inside the NavigationStack. This way, you have full control over its appearance and tap behavior, and the vertical line won’t appear because it’s not inside the List.
How to do this:
swift
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
VStack(spacing: 0) {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
// Featured article outside the List, fully customizable
if let featuredArticle = vm.articles.first {
NavigationLink(destination: ArticleDetailView(slug: featuredArticle.slug)) {
FeaturedArticleRow(article: featuredArticle)
.padding(.horizontal) // Add horizontal padding if you want
}
.buttonStyle(PlainButtonStyle()) // Remove chevron and button style
}
// The rest of the articles in a List
List {
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
.listStyle(PlainListStyle())
}
}
.task {
await vm.load()
}
}
}
}
User
That's different and it works, but now the ArticleRows scroll behind the fixed FeatureArticleRow. The first article should scroll away too.
Assistant
Great point! Since the featured article is outside the List and inside a VStack, it stays fixed at the top while the list scrolls underneath it — which is why the first article scrolls behind it.
To fix this so the featured article scrolls with the list (and scrolls away), but without the vertical line and chevron, you can:
Use a ScrollView + LazyVStack instead of List, and build the entire list manually.
This gives you full control over the appearance and behavior of every row, including the featured article, and avoids the default List styling issues.
Here’s how to do it:
swift
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
ScrollView {
LazyVStack(spacing: 0, pinnedViews: []) {
// Featured article as tappable row, no chevron or line
if let featuredArticle = vm.articles.first {
NavigationLink(destination: ArticleDetailView(slug: featuredArticle.slug)) {
FeaturedArticleRow(article: featuredArticle)
.padding(.horizontal)
.padding(.vertical, 8)
}
.buttonStyle(PlainButtonStyle()) // Remove chevron
}
// Divider between featured and rest (optional)
Divider()
.padding(.vertical, 8)
// Other articles
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
.padding(.horizontal)
.padding(.vertical, 8)
}
.buttonStyle(PlainButtonStyle()) // Remove chevron if you want
Divider()
}
}
}
.scrollIndicators(.visible) // Show scroll indicators if you want
}
}
.task {
await vm.load()
}
}
}
User
No, now we're back to having a vertical line beside the FeatureArticleRow.
What if we try something totally different again, and have a carousel of 5 FeatureArticleRows (the first 5 articles). They would still scroll away when the user goes down the list of ArticleRows of the rest of the articles.
Assistant
Got it! A carousel of featured articles at the top, scrolling away with the rest of the list, is a great idea — and it sidesteps the vertical line issue because the carousel can be a horizontally scrolling view inside the list.
Here’s the plan:
Use a horizontal ScrollView or TabView with .tabViewStyle(.page) for the carousel of the first 5 articles.
Place that carousel as a header view inside the List (or as the first row).
Then list the rest of the articles below.
This way, the carousel scrolls away naturally with the list.
No vertical line or chevron on the carousel items because you control their styling.
Example implementation:
swift
User
That kinda works, but there is a huge amount of space to the left and right of each of the carousel items. Also, there was no indicator that there were other articles
Assistant
Got it! You want a carousel with minimal side padding so the cards fill more of the horizontal space, and also a page indicator to show there are multiple items.
Here’s how to improve the carousel:
Use a TabView with .tabViewStyle(.page) for a paging carousel with page indicators.
Use .frame and .padding carefully to reduce side spacing.
Use .indexViewStyle(.page(backgroundDisplayMode: .always)) to show the page dots.
Make the carousel full width, and each card take most of the width with a bit of horizontal padding.
Updated FeaturedCarouselView with TabView and page indicator:
swift
struct FeaturedCarouselView: View {
let articles: [Article]
var body: some View {
TabView {
ForEach(articles, id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
FeaturedArticleRow(article: article)
.cornerRadius(10)
.shadow(radius: 4)
.padding(.horizontal, 8) // small horizontal padding inside each page
}
.buttonStyle(PlainButtonStyle())
}
}
.frame(height: 220) // Adjust height as needed
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .always))
.indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always))
.listRowInsets(EdgeInsets()) // Remove list insets for full width
.listRowSeparator(.hidden)
.listRowBackground(Color.clear)
}
}
How to integrate in your main view:
swift
User
The very first time my app loads, it just sits on a blank screen for 5-10 seconds. What can I do to 1) speed that up and 2) make it feel better for the user, even if I can't speed it up much?
Assistant
Great question! Long initial load times are common, especially when fetching data or doing heavy setup. Here’s how you can speed it up and improve user experience during that wait:
1) Speed up initial load
a) Optimize data loading
Load only essential data first: Instead of fetching all articles at once, fetch a smaller subset (e.g., just featured articles) initially, then load the rest in the background.
Use pagination or lazy loading: Load articles page-by-page as the user scrolls.
Cache data locally: Save previously loaded articles on disk (e.g., with Core Data, Realm, or simple file cache) and show cached data immediately while refreshing in the background.
Optimize network calls: Use efficient APIs, compress payloads, and avoid unnecessary requests.
Parallelize loading: If you have multiple resources, load them concurrently.
b) Optimize view initialization
Avoid heavy computations or synchronous work on the main thread during view init.
Use @MainActor and async/await properly to keep UI responsive.
2) Make the wait feel better (UX improvements)
a) Show a skeleton or placeholder UI
Instead of a blank screen or just a spinner, show skeleton views that mimic the layout of your content with shimmering placeholders.
This gives users a sense of progress and structure.
Or build your own simple gray rectangles with .redacted(reason: .placeholder) and .shimmer() effect.
b) Show a loading indicator with context
Use a ProgressView with a friendly message like “Loading latest articles…” or “Fetching your news…”
Add subtle animations or branding to keep it engaging.
c) Show cached or partial content immediately
If you have cached data, show it immediately while refreshing in the background.
This avoids a blank screen and gives instant feedback.
d) Use a launch screen or splash screen
User
How do I use background threads for data loading in ios 16+?
Assistant
Great question! In iOS 16+, the recommended way to perform background data loading is to use Swift’s async/await concurrency model combined with structured concurrency and task priorities. This lets you run asynchronous work off the main thread easily and safely.
How to use background threads for data loading in iOS 16+
1. Use async functions for your data loading
Make your data loading functions async so they can be awaited without blocking the main thread.
swift
class LatestViewModel: ObservableObject {
@Published var articles: [Article] = []
@Published var isLoading = false
func load() async {
isLoading = true
do {
let fetchedArticles = try await fetchArticles()
// Update UI on main thread
await MainActor.run {
self.articles = fetchedArticles
self.isLoading = false
}
} catch {
// Handle error on main thread
await MainActor.run {
self.isLoading = false
// handle error state
}
}
}
// Simulated async network fetch
func fetchArticles() async throws -> [Article] {
try await Task.sleep(nanoseconds: 2_000_000_000) // simulate delay
return [/* your articles here */]
}
}
2. Call your async load function from SwiftUI .task modifier or inside a Task
swift
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
List {
// your list content here
}
.task {
await vm.load() // runs async, off main thread
}
}
}
}
User
Right now, in my NavigationView, I have a .task { await vm.load() } - is that async?
Assistant
Yes! When you write:
swift
.task {
await vm.load()
}
inside your NavigationView (or any SwiftUI view), this is an async context.
What happens here:
The .task modifier runs its closure asynchronously when the view appears.
The closure can call await on async functions like vm.load().
The work inside vm.load() runs off the main thread if implemented properly (e.g., using async APIs).
SwiftUI manages the lifecycle of this task, cancelling it if the view disappears.
So, to answer your question:
Yes, .task { await vm.load() } is async.
It runs your load() function asynchronously.
Your load() function should be an async function that performs background work (e.g., network calls) using async/await.
Make sure inside vm.load() you update UI state on the main thread (e.g., via await MainActor.run { ... }).
.task modifier runs async code when the view appears.
Use await inside .task to call async functions.
This is the recommended way in SwiftUI to trigger async work tied to the view lifecycle.
If you want, I can review your vm.load() implementation to make sure it’s fully async and main-thread safe!
User
I like the skeleton idea, but don't want to implement it just yet.
What can I put on my screen before the ProgressView fires to show the state of my app?
Assistant
Great question! If you want to show something immediately on screen before your ProgressView appears, to avoid a blank screen and give users instant feedback, here are some simple, effective options you can use without implementing a full skeleton UI yet:
1. Show a static placeholder view or message
Display a simple placeholder UI that mimics your content layout or just a friendly message while loading starts:
if vm.isLoading && vm.articles.isEmpty {
LoadingPlaceholderView()
} else if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
// Your loaded content here
}
2. Show cached or last known data immediately (if available)
If you have any cached data, show it immediately while loading fresh data in the background. This avoids blank screens entirely.
swift
if !vm.articles.isEmpty {
// Show cached or previously loaded articles immediately
ArticleListView(articles: vm.articles)
} else if vm.isLoading {
ProgressView()
} else {
Text("No articles available.")
}
3. Show a branded splash or welcome screen
If your app has branding or a logo, show a simple branded view while loading:
swift
User
It still takes 5-10 seconds to be able to see my launch placeholder.
Assistant
If your launch placeholder (or any initial UI) doesn't appear immediately and you see a blank screen for 5-10 seconds, that usually means your app is blocked on the main thread during startup or the initial data loading is happening synchronously before SwiftUI can render anything.
Why does this happen?
Heavy synchronous work on the main thread during app launch or view initialization.
Blocking calls before the first frame is rendered.
Long-running tasks in init or onAppear that are not async.
Large data decoding or processing done synchronously.
Network calls or database fetches done synchronously.
How to fix it and show your placeholder immediately
1. Move all heavy work off the main thread
Make sure your data loading is fully async and does not block the main thread.
Use async functions with await.
Avoid synchronous network or disk I/O on the main thread.
Avoid heavy computations in initializers or property declarations.
Example:
swift
@MainActor
class LatestViewModel: ObservableObject {
@Published var articles: [Article] = []
@Published var isLoading = false
func load() async {
isLoading = true
do {
let fetched = try await fetchArticles()
articles = fetched
} catch {
// handle error
}
isLoading = false
}
}
And call it with .task modifier:
swift
.task {
await vm.load()
}
2. Avoid doing work in init or synchronous property initializers
If your view model or views do heavy work in init, move that to an async method called later.
3. Use the launch screen storyboard for immediate UI
iOS shows the launch screen storyboard before your app code runs. Make sure your launch screen storyboard is designed to look like your placeholder or initial UI.
User
The time between app init and ContentView appearing was quite short. The longest amount of time was before App Init. How do I debug that?
Assistant
Great observation! If the longest delay is before your app’s init or before ContentView appears, that means the bottleneck is happening very early in the app launch process, before your SwiftUI code runs.
If you have global variables or static properties that do expensive work (e.g., decoding JSON, loading files, initializing large data structures), these run before your app’s init.
Example:
swift
let bigData = try! JSONDecoder().decode(..., from: someFile) // runs at app launch
2. Large or complex launch screen storyboard
If your launch screen storyboard is complex or references large images, it can slow down launch.
3. App startup time due to linked frameworks
Large frameworks or many dependencies can increase launch time.
4. App signing, encryption, or system-level delays
Rare but possible, especially on first launch or after install.
How to debug and fix this early delay
1. Profile app launch with Instruments
Open Xcode.
Product > Profile > Choose Time Profiler.
Select your app.
In Instruments, choose Launch Time template or manually record from app launch.
Look at the call tree and time spent before main() or before your app code runs.
Identify any heavy static initializers or framework loading.
2. Check for heavy global/static initializers
Search your code for global variables or static properties that do work.
Move any heavy work into lazy properties or async functions called later.
User
I have 4 custom fonts installed. Are they slowing things down?
Assistant
Great question! Custom fonts can impact app launch performance, but usually the effect is small unless fonts are very large or used inefficiently.
How custom fonts affect launch time:
When you include custom fonts in your app bundle, iOS registers and loads them at app launch.
If you have many fonts or very large font files, this can add some overhead.
Using many font weights/styles (e.g., 4 fonts × multiple weights) increases the number of font files.
If fonts are used in your launch screen storyboard or initial views, they must be loaded immediately, which can add delay.
Fonts loaded dynamically or lazily (e.g., via UIFont.register) can reduce upfront cost but add complexity.
Are 4 custom fonts a big problem?
Usually not. Four well-optimized font files typically add only a small fraction of a second to launch.
If your fonts are large (several MB each) or you bundle many variants, it can add up.
The biggest impact is if fonts are used in the launch screen storyboard or very early UI.
How to check if fonts are slowing you down
Profile app launch with Instruments Time Profiler
Look for calls related to font loading or CoreText.
Test launch time without custom fonts
Temporarily remove or comment out font registrations and see if launch time improves.
Check font file sizes
Large .ttf or .otf files (>1MB each) can slow loading.
How to optimize font loading
Subset fonts: Use only the characters and weights you need (tools like Glyphhanger or font subsetting services).
Use fewer font weights/styles: Limit to essential variants.
Avoid using custom fonts in launch screen storyboard: Use system fonts or simple graphics instead.
Lazy load fonts if possible: Register fonts programmatically when needed (more complex).
Summary
Factor
Impact on launch time
Recommendation
Number of fonts (4 is moderate)
User
I'm testing the app on a iphone that is connecting to xcode over wifi. How can I do time profiling?
Assistant
Great question! Profiling an app running on a physical iPhone connected over Wi-Fi is absolutely possible with Xcode Instruments, but there are some important tips to get smooth and accurate profiling.
How to do Time Profiling on an iPhone connected over Wi-Fi
1. Connect your iPhone to your Mac via USB first
To enable wireless debugging, you must first connect your iPhone via USB cable.
In Xcode, select your device, then enable Connect via network in the device info pane.
Once enabled, you can unplug the cable and continue debugging/profiling over Wi-Fi.
2. Launch Instruments and select your device
Open Xcode.
Product > Profile (or press Cmd+I).
In the Instruments app that opens, select your iPhone device from the device dropdown in the toolbar.
Make sure your iPhone is connected over Wi-Fi (you’ll see a Wi-Fi icon next to the device name).
3. Choose the Time Profiler instrument
Select Time Profiler from the list of instruments.
Click Record to start profiling.
4. Launch your app on the device
If your app is not already running, launch it from Instruments or from the device.
Instruments will start collecting CPU usage and call stack samples.
5. Tips for smooth profiling over Wi-Fi
Keep your Mac and iPhone close to the same Wi-Fi network with strong signal.
Avoid heavy network traffic on your Wi-Fi to reduce latency.
Be patient: profiling over Wi-Fi can be slower and less stable than USB.
If you experience dropped connections or lag, reconnect via USB and try again.
6. Analyze launch time
To profile app launch specifically, you can:
Launch the app from Instruments (using the Launch Executable option).
Or manually start recording and then launch the app on the device.
Look for the main thread activity and time spent before your app’s init.
Use the call tree and stack traces to identify bottlenecks.
Summary
Step
Notes
User
My console shows this:
load_eligibility_plist: Failed to open /Users/dfdc/Library/Developer/CoreSimulator/Devices/9D7DB54B-7771-46B8-80C2-AA995183D0A1/data/Containers/Data/Application/AAE023A8-4B92-4C71-AF4E-0F0B136B2CB9/private/var/db/eligibilityd/eligibility.plist: No such file or directory(2)
Assistant
The console message:
code
load_eligibility_plist: Failed to open /Users/dfdc/Library/Developer/CoreSimulator/Devices/9D7DB54B-7771-46B8-80C2-AA995183D0A1/data/Containers/Data/Application/AAE023A8-4B92-4C71-AF4E-0F0B136B2CB9/private/var/db/eligibilityd/eligibility.plist: No such file or directory(2)
is a known benign warning that appears in the iOS Simulator logs. It indicates that the system tried to access a file related to eligibilityd (an internal Apple daemon/service) but the file does not exist in the simulator environment.
What does this mean?
This is not an error in your app.
It is related to internal system services on the Simulator.
It does not affect your app’s functionality or performance.
It is safe to ignore.
Why does it happen?
The Simulator environment sometimes lacks certain system files or directories that exist on real devices.
Some system daemons try to read these files and log a warning when they are missing.
This is common and expected behavior in Simulator logs.
What should you do?
Ignore this message unless you see related crashes or functional issues.
If you want to reduce noise, you can filter out this log in your console.
Test on a real device to confirm your app is unaffected.
Summary
Message
Meaning
Action
load_eligibility_plist: Failed to open ...
Simulator internal warning
Ignore safely
If you see other errors or your app behaves unexpectedly, feel free to share those logs!
Fix using programmatic navigation (if you want to control navigation explicitly):
Remove the NavigationLinks inside the list and instead use a Button or onTapGesture to set selectedArticleSlug, then use .navigationDestination to navigate.
swift
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
@State private var selectedArticleSlug: String? = nil
var body: some View {
NavigationStack {
List {
VStack {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
if let featuredArticle = vm.articles.first {
Section {
Button {
selectedArticleSlug = featuredArticle.slug
} label: {
FeaturedArticleRow(article: featuredArticle)
}
.buttonStyle(PlainButtonStyle()) // To avoid button styling
}
}
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
Button {
selectedArticleSlug = article.slug
} label: {
ArticleRow(article: article)
}
.buttonStyle(PlainButtonStyle())
}
}
}
.task {
await vm.load()
}
}
.listStyle(PlainListStyle())
.navigationDestination(for: String.self) { slug in
ArticleDetailView(slug: slug)
}
}
}
}
Summary
Do not mix NavigationLink and programmatic navigation for the same destination.
Use either NavigationLink directly or programmatic navigation with .navigationDestination and a state variable.
Your original code had both, causing multiple views to open simultaneously.
Let me know if you want me to help with a specific approach!
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
List {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
if let featuredArticle = vm.articles.first {
Section {
NavigationLink(destination: ArticleDetailView(slug: featuredArticle.slug)) {
FeaturedArticleRow(article: featuredArticle)
}
.buttonStyle(PlainButtonStyle()) // Remove chevron
.listRowSeparator(.hidden) // Hide separator
.listRowBackground(Color.clear) // Optional: clear background
}
}
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.listStyle(PlainListStyle())
.task {
await vm.load()
}
}
}
}
Summary:
.buttonStyle(PlainButtonStyle()) removes the default button appearance including the chevron.
.listRowSeparator(.hidden) hides the separator line for that row.
.listRowBackground(Color.clear) removes the default background color (optional, but often looks cleaner).
This keeps the featured article tappable without the ugly line and chevron.
If you want me to help with any other styling tweaks, just ask!
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
List {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
if let featuredArticle = vm.articles.first {
Section {
NavigationLink(destination: ArticleDetailView(slug: featuredArticle.slug)) {
FeaturedArticleRow(article: featuredArticle)
}
.buttonStyle(PlainButtonStyle())
.listRowSeparator(.hidden)
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets()) // <-- This removes the vertical line
}
}
ForEach(vm.articles.dropFirst(), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.listStyle(PlainListStyle())
.task {
await vm.load()
}
}
}
}
Explanation:
.listRowInsets(EdgeInsets()) removes all padding around the row content, so the row fills the full width.
This removes the vertical line that appears due to the default inset and background styling.
Combined with .listRowSeparator(.hidden) and .buttonStyle(PlainButtonStyle()), you get a clean tappable featured article row with no chevron or lines.
Try this and the vertical line should be gone! Let me know if you want it styled differently or have other questions.
Why remove the Section?
Section adds its own styling and background which can cause the vertical line.
Removing it lets you control the row appearance fully.
If you want a header for the featured article, add a separate Text or custom header view outside the Section.
Bonus: If you want to debug the background, add a colored background temporarily:
swift
.listRowBackground(Color.red.opacity(0.3))
to see where the background and insets are applied.
Summary:
Remove the Section around the featured article.
Use .listRowInsets(EdgeInsets()) to remove padding.
Use .listRowSeparator(.hidden) to hide separators.
Use .listRowBackground(Color.clear) to remove background.
Use .buttonStyle(PlainButtonStyle()) to remove chevron.
If you want, I can prepare a full minimal example with dummy data to test this exact behavior. Would you like that?
Why this works:
The featured article is not inside the List, so no list row styling, no separators, no vertical lines.
You keep the tappable NavigationLink with .buttonStyle(PlainButtonStyle()) to remove the chevron.
The rest of the articles remain in the List with normal styling.
You can style the featured article row however you want, with full control.
Optional: Add a divider or spacing between featured article and list if you want a visual separation.
swift
Divider()
.padding(.vertical, 8)
Summary:
Move the featured article out of the List.
Use a NavigationLink with PlainButtonStyle for tap behavior without chevron.
Keep the rest of the articles in the List.
This avoids all the weird list styling issues for the featured article.
If you want, I can help you polish this further or add animations, headers, etc. Just ask!
Why this works:
ScrollView + LazyVStack lets you build a fully custom scrollable list.
No default List styling, so no vertical lines or chevrons unless you add them.
The featured article scrolls with the rest of the articles.
You control padding, dividers, and spacing exactly.
NavigationLink inside ScrollView works fine for navigation.
Optional improvements:
Add custom separators (like Divider()) between rows.
Adjust padding to your design.
Add headers or section titles as needed.
Summary:
Replace List with ScrollView + LazyVStack for full control.
Put featured article as first item in the stack.
Use NavigationLink with .buttonStyle(PlainButtonStyle()) to remove chevrons.
Add dividers manually if you want separators.
If you want, I can help you style the dividers or add section headers next!
import SwiftUI
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
List {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
// Carousel of first 5 featured articles
if !vm.articles.isEmpty {
FeaturedCarouselView(articles: Array(vm.articles.prefix(5)))
.listRowInsets(EdgeInsets()) // Remove insets for full width
.listRowSeparator(.hidden) // Hide separator
.listRowBackground(Color.clear)
}
// The rest of the articles
ForEach(vm.articles.dropFirst(5), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.listStyle(PlainListStyle())
.task {
await vm.load()
}
}
}
}
// Carousel view showing horizontally scrollable featured articles
struct FeaturedCarouselView: View {
let articles: [Article] // Your article model
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(spacing: 16) {
ForEach(articles, id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
FeaturedArticleRow(article: article)
.frame(width: 300) // Fixed width for carousel cards
.cornerRadius(10)
.shadow(radius: 4)
}
.buttonStyle(PlainButtonStyle()) // Remove chevron
}
}
.padding(.horizontal)
.padding(.vertical, 8)
}
.frame(height: 200) // Adjust height as needed
}
}
Explanation:
FeaturedCarouselView is a horizontally scrolling ScrollView with a fixed height.
Each featured article is a card (FeaturedArticleRow) inside a NavigationLink with PlainButtonStyle() to remove chevrons.
The carousel is embedded as the first row in the List with no insets or separators.
The rest of the articles start after the carousel.
The carousel scrolls away naturally when the user scrolls down the list.
Benefits:
No vertical line or chevron on carousel items.
Carousel looks like a distinct, visually appealing section.
Works well with List and NavigationStack.
Easy to customize carousel item size, spacing, and style.
If you want, I can help you add page-style snapping with TabView or fancier carousel effects next! Would you like that?
List {
if vm.isLoading {
ProgressView()
.progressViewStyle(CircularProgressViewStyle())
.padding()
} else {
if !vm.articles.isEmpty {
FeaturedCarouselView(articles: Array(vm.articles.prefix(5)))
}
ForEach(vm.articles.dropFirst(5), id: \.slug) { article in
NavigationLink(destination: ArticleDetailView(slug: article.slug)) {
ArticleRow(article: article)
}
}
}
}
.listStyle(PlainListStyle())
.task {
await vm.load()
}
Why this works better:
TabView with .page style creates a paging carousel with dots.
Cards take most of the width, with only 8 points padding on each side.
Page indicator dots show below the carousel.
No extra large side padding.
The carousel scrolls away naturally with the list.
Optional tweaks:
Adjust .frame(height:) to fit your FeaturedArticleRow design.
Adjust .padding(.horizontal, 8) inside the card to control spacing between pages.
You can customize the page indicator color with .indexViewStyle(PageIndexViewStyle(backgroundDisplayMode: .always)).
If you want, I can help you add a peek effect (show part of next/previous card) or custom page indicator styling! Just ask.
iOS launch screens show instantly on app start, so design a launch screen that matches your app’s style.
This reduces perceived load time.
Example: Skeleton + async loading in SwiftUI
swift
struct LatestListViewTest: View {
@StateObject private var vm = LatestViewModel()
var body: some View {
NavigationStack {
Group {
if vm.isLoading && vm.articles.isEmpty {
// Show skeleton placeholders while loading first time
SkeletonListView()
} else {
// Show actual content
List {
// Your featured carousel and articles here
}
.listStyle(PlainListStyle())
}
}
.task {
await vm.load()
}
}
}
}
struct SkeletonListView: View {
var body: some View {
VStack(spacing: 16) {
ForEach(0..<5) { _ in
RoundedRectangle(cornerRadius: 8)
.fill(Color.gray.opacity(0.3))
.frame(height: 100)
.redacted(reason: .placeholder)
.shimmer() // You can implement a shimmer effect or use a package
}
}
.padding()
}
}
Summary checklist
Action
Benefit
Load minimal data first
Faster initial display
Cache and show cached data
Instant content on launch
Use skeleton placeholders
Better perceived performance
Show progress with context
Keeps user informed
Optimize network and parsing
Real speed improvements
Use launch screen
Smooth app start experience
If you want, I can help you implement caching or skeleton loading in your app! Just ask.
3. Use Task with priority if needed
You can specify task priority to hint the system about importance:
swift
Task(priority: .background) {
await vm.load()
}
But usually .task modifier is enough.
4. Avoid blocking the main thread
Don’t do synchronous network or heavy work on the main thread.
Use async APIs (URLSession.shared.data(from:) is async in iOS 15+).
Use await to suspend the current task instead of blocking.
5. Example: Async network fetch with URLSession
swift
func fetchArticles() async throws -> [Article] {
let url = URL(string: "https://api.example.com/articles")!
let (data, _) = try await URLSession.shared.data(from: url)
let articles = try JSONDecoder().decode([Article].self, from: data)
return articles
}
Summary
Step
How to do it
Make data loading async
Use async functions
Call from SwiftUI
Use .task { await vm.load() }
Update UI on main thread
Use await MainActor.run { ... }
Use async URLSession
try await URLSession.shared.data(from:)
Use Task(priority:) if needed
For background priority tasks
If you want, I can help you refactor your existing data loading code to use async/await properly!
struct SplashLoadingView: View {
var body: some View {
VStack {
Image("AppLogo")
.resizable()
.scaledToFit()
.frame(width: 120, height: 120)
Text("Fetching your news...")
.font(.title3)
.foregroundColor(.secondary)
}
.padding()
}
}
4. Show a minimal static layout with placeholders
You can show your actual UI layout but with static placeholders (e.g., gray boxes or text like “Loading…”), so the user sees the structure immediately.
Avoids blank screen: Users see something immediately.
Sets expectations: They know content is coming.
Feels faster: Even if loading takes a few seconds, the UI feels responsive.
Summary
Option
When to use
Static placeholder view
Quick, easy, no extra logic
Cached data
If you have offline or cached data
Branded splash screen
For strong branding experience
Minimal static layout
Prepares user for content structure
If you want, I can help you add a simple placeholder or cached data display to your current view!
This gives users instant visual feedback while your app loads.
4. Show a very lightweight initial view
Your initial SwiftUI view should be as lightweight as possible — just a simple Text or static image — so it renders immediately.
5. Profile your app startup
Use Xcode Instruments (Time Profiler) or the Debug Navigator to check if your main thread is blocked during launch.
Look for:
Long synchronous calls.
Heavy JSON decoding.
Large image loading.
Blocking disk or network I/O.
Summary checklist to fix slow initial UI:
Step
What to do
Make data loading fully async
Use async/await, no blocking calls
Move heavy work out of init
Use async methods called after view appears
Design launch screen storyboard
Show placeholder UI instantly on launch
Keep initial SwiftUI view simple
Minimal UI to render immediately
Profile startup
Find and fix main thread blocking
Quick test you can do:
Replace your main view body temporarily with just:
swift
Text("Loading...")
.font(.largeTitle)
If you still see a blank screen for several seconds before this text appears, the problem is definitely blocking work before SwiftUI renders.
If you want, I can help you audit your code or suggest concrete refactors to fix this startup delay! Just share your view model or app launch code.
Example:
swift
// Bad: runs at app launch
let cachedArticles: [Article] = loadArticlesFromDisk()
// Better: lazy load or async load later
lazy var cachedArticles: [Article] = loadArticlesFromDisk()
3. Simplify your launch screen
Use a simple launch screen storyboard with minimal views and no large images.
Prefer vector assets or simple shapes.
Avoid complex layouts or animations.
4. Use os_signpost or logging
Add logging or signposts in your app delegate or @main struct to measure how long each step takes.
Example:
swift
import os
let log = OSLog(subsystem: "com.yourapp", category: "launch")
@main
struct YourApp: App {
init() {
os_signpost(.begin, log: log, name: "App Init")
// your init code
os_signpost(.end, log: log, name: "App Init")
}
var body: some Scene {
WindowGroup {
ContentView()
.task {
os_signpost(.begin, log: log, name: "ContentView Load")
// load data
os_signpost(.end, log: log, name: "ContentView Load")
}
}
}
}
Then use Instruments to see these signposts.
Summary
Step
How to debug/fix
Profile launch with Instruments
Find where time is spent before app init
Check global/static initializers
Move heavy work out of global scope
Simplify launch screen storyboard
Use minimal UI, avoid large images
Add logging/signposts
Measure app init and view load times
If you want, I can help you review your app’s static/global code or launch screen to spot potential slowdowns! Just share relevant code or storyboard details.
Small to moderate
Usually fine, but test to confirm
Font file size (large files)
Can add noticeable delay
Subset or optimize font files
Using fonts in launch screen
Forces immediate font loading
Avoid custom fonts in launch screen
Many font weights/styles
Increases total font files loaded
Limit to essentials
Bottom line
4 custom fonts alone are unlikely to cause a 5-10 second launch delay. But if your font files are large or used in the launch screen, they could contribute.
If you want, I can help you:
Analyze your font files.
Suggest subsetting or optimization.
Review your launch screen for font usage.
Just share your font details or launch screen setup!
Connect iPhone via USB first
Required to enable wireless debugging
Enable “Connect via network”
In Xcode Devices and Simulators window
Launch Instruments
Product > Profile
Select your iPhone device
Should show Wi-Fi icon if connected
Choose Time Profiler
For CPU and launch time profiling
Start recording and launch app
Analyze collected data
If you want, I can guide you through interpreting the Time Profiler results or setting up custom signposts to measure specific parts of your app launch!