Explore the various UI frameworks available for building app interfaces. Discuss the use cases for different frameworks, share best practices, and get help with specific framework-related questions.

All subtopics

Post

Replies

Boosts

Views

Activity

not work paragraphStyle in AttributedString
I tried to create a Text View using attributedString. I want to set the line height using paragraphStyle and return the Text, but paragraphStyle is not being applied. Why is that? extension Text { init?(_ content: String, font: StyleType, color: Color = .ppBlack) { var attributedString = AttributedString(content) attributedString.font = Font.custom(font.fontWeight, fixedSize: font.fontSize) attributedString.foregroundColor = color let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.minimumLineHeight = 16 paragraphStyle.maximumLineHeight = 16 paragraphStyle.lineSpacing = 0 attributedString.mergeAttributes(.init([.paragraphStyle: paragraphStyle])) self = Text(attributedString) } }
1
0
123
1w
What does the @__EntryDefaultValue macro expand to?
In Xcode 16.0 and 16.1, it was clear how @Entry macro works from the generated code. If you explicitly specify the type, then defaultValue is a computed property, if you do not specify the type, then a stored property. In Xcode 16.2, @__EntryDefaultValue has been added to the generated code, which Xcode does not want to expand. Visually, it seems that a stored property is generated, but the behavior shows that as a result we have a computed property, and for both options: with an explicit type and without an explicit type. So the question is: what does this @__EntryDefaultValue macro generate and is the result a bug? Or was it a bug in previous versions of Xcode?
1
0
160
1w
NSHostingView doesn't work when used as an accessory view for NSOpenPanel
Our app presents an NSOpenPanel with an accessory view implemented in SwiftUI and presented via NSHostingView. TextFields and pickers are working OK, but Buttons and Toggles (checkboxes) aren’t, although Toggles styled with .switch are functioning as expected. Specifically: Toggles styled with .checkbox fail with no feedback. Overriding NSHostingView mouseDown() shows that the mouse event is completely ignored by the Toggle Buttons “see” the mouseDown event (the button highlights when pressed, and the event doesn’t fall through to the hosting view), but the button action isn’t triggered until the dialog is dismissed Any idea on how to get these controls functional?
3
0
114
1w
iOS Architecture Research - Help a student
Hi everyone! I'm thrilled to share that I'm conducting a field research as part of my final university project, focused on iOS architecture. The goal is to dive deeper into the best practices, challenges, and trends in the iOS development world. To make this research truly impactful, I need your help! If you're an iOS developer, I’d love it if you could take a few minutes to answer a short survey. Your insights and experiences will be invaluable for my research, and I greatly appreciate your support! Here is the link: https://docs.google.com/forms/d/e/1FAIpQLSdf9cacfA7my1hnlazyl7uJraa2oTsQ7dJBWvFtZ_4vbYenRA/viewform?usp=send_form Thank you so much in advance for helping me out—feel free to share this post with others who might also be interested. Let’s build something amazing together! 💡✨
0
0
98
1w
Swift ObservableObject implementation with generic inference
I must admit my knowledge of swift is limited, and I cannot wrap my head around this problem. I've defined this protocol, so I can use different auth providers in my app. protocol AuthRepository { associatedtype AuthData associatedtype AuthResponseData associatedtype RegistrationData associatedtype RegistrationResponseData func login(with data: AuthData) async throws -> AuthResponseData? func register(with data: RegistrationData) async throws -> RegistrationResponseData? } and an implementation for my server struct MyServerAuthData { let email: String let password: String } struct MyServerAuthResponseData { let token: String } struct MyServerRegistrationData { let email: String let password: String let name: String } actor AuthRepositoryImpl: AuthRepository { func login(with data: MyServerAuthData) async throws -> MyServerAuthResponseData? { ... } func register(with data: MyServerRegistrationData) async throws -> Void? { ... } } To use across the app, I've created this ViewModel @MainActor final class AuthViewModel<T: AuthRepository>: ObservableObject { private let repository: T init(repository: T) { self.repository = repository } func login(data: T.AuthData) async throws -> T.AuthResponseData? { try await repository.login(with: data) } func register(with data: T.RegistrationData) async throws { try await repository.register(with: data) } } defined in the app as @main struct MyApp: App { @StateObject var authViewModel = AuthViewModel(repository: AuthRepositoryImpl()) var body: some Scene { WindowGroup { ContentView() .environmentObject(self.authViewModel) } } } and consumed as @EnvironmentObject private var authViewModel: AuthViewModel<AuthRepositoryImpl> But with this code, the whole concept of having a generic implementation for the auth repository is useless, because changing the AuthRepostory will need to search and replace AuthViewModel<AuthRepositoryImpl> across all the app. I've experienced this directly creating a MockAuthImpl to use with #Preview, and the preview crashed because it defines AuthViewModel(repository: MockAuthImpl()) but the view expects AuthViewModel. There is a better way to do that?
1
0
111
1w
After building the project, the search form does not allow typing, but pasting works.
When I created a search box on the homepage, I was able to enter text in the input field while previewing in Xcode. However, after clicking "Build" and running the app, I couldn't type anything into the input field in the demo interface. Additionally, I received the following error message: If you want to see the backtrace, please set CG_NUMERICS_SHOW_BACKTRACE environmental variable. Error: this application, or a library it uses, has passed an invalid numeric value (NaN, or not-a-number) to CoreGraphics API and this value is being ignored. Please fix this problem. How can I fix this issue? Here is my ContentView.swift code: import SwiftUI struct ContentView: View { @State private var searchText: String = "" @State private var isSearching: Bool = false var body: some View { NavigationStack { GeometryReader { geometry in VStack { Spacer() .frame(height: geometry.size.height.isNaN ? 0 : geometry.size.height * 0.3) VStack(spacing: 20) { Text("NMFC CODES LOOKUP") .font(.title2) .bold() TextField("Search...", text: $searchText) .textFieldStyle(PlainTextFieldStyle()) .padding(10) .frame(height: 40) .frame(width: geometry.size.width.isNaN ? 0 : geometry.size.width * 0.9) .background(Color.white) .cornerRadius(8) .overlay( HStack { Spacer() if !searchText.isEmpty { Button(action: { searchText = "" }) { Image(systemName: "xmark.circle.fill") .foregroundColor(.gray) .padding(.trailing, 8) } } } ) .overlay( RoundedRectangle(cornerRadius: 8) .stroke(Color.gray.opacity(0.5), lineWidth: 1) ) Button(action: { isSearching = true }) { Text("Search") .foregroundColor(.white) .frame(width: geometry.size.width * 0.9, height: 40) .background(Color.blue) .cornerRadius(8) } .disabled(searchText.isEmpty) Text("Created & Designed & Developed By Matt") .font(.caption) .foregroundColor(.gray) .padding(.top, 10) } Spacer() .frame(height: geometry.size.height * 0.7) } .frame(width: geometry.size.width) } .background(Color(red: 250/255, green: 245/255, blue: 240/255)) .navigationDestination(isPresented: $isSearching) { SearchResultsView(searchQuery: searchText) } } .background(Color(red: 250/255, green: 245/255, blue: 240/255)) .ignoresSafeArea() } } #Preview { ContentView() }
4
0
153
1w
[iOS, SwiftUI] UiRefreshControl.tintColor is not the same as given one
Hello! I'm trying to set a UiRefreshControl.tintColor: .onAppear { UIRefreshControl.appearance().tintColor = UIColor.systemBlue } But instead of I get The color in the second picture is a high contrast version of the first one. I can't understand why it works this way. I also tried the following. UIRefreshControl.appearance().tintColor = UIColor(red: 0, green: 0.478, blue: 1, alpha: 1) // doesn't work UIRefreshControl.appearance().tintColor = UIColor(named: "RefreshControlColor") // doesn't work, here set "High contrast" on and indicated Universal.systemBlueColor Perhaps I missed something?
0
0
83
1w
Conflict between offerCodeRedemption and Camera
Hello, I implemented offerCodeRedemption recently on my app in my subscription/onboarding flow. When I did, it broke my camera functionality (elsewhere in the app; totally unrelated code). I was able to fix the issue when implementing the old "AppStore.presentOfferCodeRedeemSheet" code with UIKit. I'm not sure why this is happening, but it seemed like a bug to me.
0
0
76
1w
SwiftUI Table column widths cannot be saved
I have a macOS app made with SwiftUI where I want to show a list of data in a tabular fashion. SwiftUI Table seems to be the only built-in component that can do this. I would like to let the user size the columns and have their widths restored when the app is relaunched. I can find no documentation on how to do this and it does not seem to be saved and restored automatically. I can find no way to listen for changes in the column widths when the user resizes and no way to set the size from code. For a macOS app it seems that the only way to set the width of a column is to use e.g. .width(min: 200, max: 200). This in effect disables resizing of the column. It seems that idealSize is totally ignored on macOS. Any suggestions?
2
2
160
1w
Note app UI bug
I found a bug in the notes app where if you click on a note the “all iCloud” text will cover over the “all folders” back button and also the “all iCloud” will also hover over the undo button
1
0
144
1w
Suggestion to Add Performance Metrics for SwiftUI in XCTest
As SwiftUI adoption grows, developers face challenges in effectively measuring and optimizing SwiftUI app performance within automated tests. Currently, the only viable approach to analyzing SwiftUI performance is through Profiling (Instruments), which, while powerful, lacks the ability to be incorporated into automated testing workflows. It would be incredibly valuable if XCTest could introduce new performance metrics specifically tailored for SwiftUI, allowing us to write tests against common performance bottlenecks. Suggested Metrics: View Body Evaluation Count – Tracks how often a SwiftUI body is recomputed to detect unnecessary re-renders. Slow View Bodies – Flags SwiftUI views that take a significant amount of time to compute their body. These metrics would help developers identify inefficiencies early, enforce performance best practices through CI/CD pipelines, and ensure a smooth user experience. I believe adding these performance metrics would be a game-changer for SwiftUI development. Thank you for your time and consideration!
1
0
171
1w
AVQueuePlayer Error: LoudnessManager.mm:709 unable to open stream for LoudnessManager plist
Getting this error in iPhone Portrait Mode with notch. Currrently using AVQueuePlayer to play more than 30 mp3 files one by one. All constraint properties are correct but error occures only in Apple iPhone Portrait Mode with notch series. But same code works on same iPhone in Landscape mode. **But I get this error: ** LoudnessManager.mm:709 unable to open stream for LoudnessManager plist Type: Error | Timestamp: 2025-02-07 | Process: | Library: AudioToolbox | Subsystem: com.apple.coreaudio | Category: aqme | TID: 0x42754 LoudnessManager.mm:709 unable to open stream for LoudnessManager plist LoudnessManager.mm:709 unable to open stream for LoudnessManager plist Timestamp: 2025-02-07 | Library: AudioToolbox | Subsystem: com.apple.coreaudio | Category: aqme
0
0
144
1w
macOS Menu disappears when converting from NSApplicationActivationPolicyAccessory to NSApplicationActivationPolicyRegular if display disconnected and reconnected
I'm not quite sure where the problem is, but I will describe what I am doing to recreate the issue, and am happy to provide whatever information I can to be more useful. I am changing the ActivationPolicy for my app in order to make it unobtrusive when in the background (e.g. hiding it from the dock and using only a menu bar status item). When the user activates the app with a hotkey, it changes from NSApplicationActivationPolicyAccessory back to NSApplicationActivationPolicyRegular. This allows normal usage (dock icon, menu bar, etc.) This works fine, except in a rare situation which I finally just tracked down. If there is a window open in the app and I use the hotkey to convert back to an accessory, and then disconnect and reconnect the display on which the app was previously displayed, when I convert the app back to "regular mode", the menu bar has disappeared (and I am left with an empty space at the top of the screen). I can also trigger this bug by having the display in question briefly mirror the other display (effectively "orphaning" the hidden app), and then restoring the original side-by-side configuration before activating the app again. The app otherwise works, but the menu bar is missing. Switching back and forth with other apps does not fix the problem. Quitting and restarting the app resolves the issue. As does disabling the accessory only mode and forcing the app to always remain in "regular mode" with a dock icon (there is a preference for this in my app). Once fixed, I can then re-enable the "accessory mode" and all is well until the bug is triggered again. The bug would normally occur quite sporadically, presumably requiring a particular combination of changing Spaces or displays, or having the computer go to sleep while this app was in accessory mode. Thus far, the above is the only way I have found that can replicate this issue on demand. If I close all windows before hiding the app, then it works fine when I revert to "regular mode". It only happens if there is a window open at the time. Using applicationDidChangeScreenParameters: on my AppDelegate indicates that there is a change in screen, and logging window.screen.frame for each open window in [NSApp orderedWindows] shows that the size changes from e.g. 1920x1080 to 0x0 and back while the display is disconnected or mirrored. There is also an error in the console in Xcode when this happens -- invalid display identifier <some UUID>. I have tried various options for window collectionBehavior, as well as various settings for Spaces (which I normally use). None of these changes has fixed the behavior thus far. I use [NSApp hide:self]; from my AppDelegate to hide the app, and [[NSRunningApplication currentApplication] activateWithOptions:NSApplicationActivateAllWindows];[NSApp unhide:self]; to bring it back to the front. I welcome any ideas for things to chase down, or requests for more specific information that would be useful. Thank you! Fletcher
1
0
149
1w
Adding Markdown support in notes app
Hi guys, I’m making a simple note taking app and I want to support markdown functionality. I have tried to find libraries and many other GitHub repos but some of them are slow and some of them are very hard to implement and not very customizable. In WWDC 22 apple also made a markdown to html document app and I also looked at that code and it was awesome. It was fast and reliable (Apple btw). But the only problem I am facing is that the markdown text is on the left side and the output format is on the right in the form of html. I don’t want that I want both in the same line. In bear notes and things 3 you can write in markdown and you can see that it is converting in the same line. I have also attached example videos. So, I have markdown parser by apple but the only thing in the way is that it is converting it into a html document. Please help me with this. Also please look into the things 3 video they have also completely customized the text attributes selection menu. By default with UITextView we can only enable text attributes and it shows like this. By clicking more we get the complete formatting menu but not the slider menu which is more convenient. Please also help me this. I don’t know if I can provide apple file but it is from wwdc 22 supporting desktop class interaction
0
0
160
1w
SwiftUI: toolbar jump weirdly in AppleWatch
Here is the reproducible codes: struct JumpView: View { var body: some View { NavigationStack { TabView { Text("Jump") .toolbar { ToolbarItem(placement: .topBarLeading) { Button("Done") {} } } } } } } Run directly in real apple watch device in watchOS 10.0+ (do not debug connecting with Xcode). When raise your wrist the ToolBar Button will jump weirdly.
1
0
163
1w
Task cancellation behaviour
Hi everyone, I believe this should be a simple and expected default behavior in a real-world app, but I’m unable to make it work: 1. I have a View (a screen/page in this case) that calls an endpoint using async/await. 2. If the endpoint hasn’t finished, but I navigate forward to a DetailView, I want the endpoint to continue fetching data (i.e., inside the @StateObject ViewModel that the View owns). This way, when I go back, the View will have refreshed with the fetched data once it completes. 3. If the endpoint hasn’t finished and I navigate back to the previous screen, I want it to be canceled, and the @StateObject ViewModel should be deinitialized. I can achieve 1 and 3 using the .task modifier, since it automatically cancels the asynchronous task when the view disappears: view .task { await vm.getData() } I can achieve 1 and 2 using a structured Task in the View (or in the ViewModel, its the same behavior), for example: .onFirstAppearOnly { Task { away vm.getData() } } onFirstAppearOnly is a custom modifier that I have for calling onAppear only once in view lifecycle. Just to clarify, dont think that part is important for the purpose of the example But the question is: How can I achieve all three behaviors? Is this really such an unusual requirement? My minimum deployment target is iOS 15, and I’m using NavigationView + NavigationLink. However, I have also tried using NavigationStack + NavigationPath and still couldn’t get it to work. Any help would be much appreciated. Thank you, folks!
0
0
148
1w
How to solve "Extra trailing closure passed in call" in a section?
Hey there, I'm new to Swift and currently building my first app. I'm having the error "Extra trailing closure passed in call" in a section and already compared it to working sections and just can't find the error in my code. Maybe you guys can help me: Form { Section("Essential Information") { TextField("Title", text: $title) TextField("Composer", text: $composer) TextField("Opus", text: $opus) } The error is occurring in the section line. There are over sections that work perfectly fine: Section("Additional Details") { TextField("Epoch", text: $epoch) TextField("Type", text: $type) TextField("Accompaniment", text: $accompaniment) TextField("Length (minutes)", value: $length, format: .number) .keyboardType(.numberPad) TextField("Key", text: $key) TextField("Difficulty", text: $difficulty) TextField("Tempo (BPM)", value: $tempo, format: .number) .keyboardType(.numberPad) }
2
0
156
1w
[iOS, SwiftUI] Navigation Bar background is always hidden when navigation destination is TabView
Hello! I have a destination navigation which is TabVIew where each tab item is ScrollView. And when scrolling content of any of tab items is underneath navigation bar its background is always hidden. But at the same time tab bar background is toggled depending on scrolling content position. I expected it would work with TabView the same as with any other view. Is it supposed to work like that?
2
0
159
1w