Post

Replies

Boosts

Views

Activity

TextField set behavior request
Hello there! I come from Objective-C and there I could have an NSTextField set to not be editable or selectable: NSTextField *outputfield; [outputfield setEditable:false]; [outputfield setSelectable:false]; You can do the same in Xcode's Interface Builder panel and select options from a Picker to (Selectable, Editable or None): There is no way to achieve this in SwiftUI and the only option you have is to set a TextField() as .disabled which is not the same. I often used this setters to have an evenly looking form but where only output text (that's not meant to be edited) is show but is clearly visible. The text inside a .disabled text field has no contrast and is not clearly visible. Therefore I would like to request an addition of these two modifiers: selectable(_ selectable: Bool) editable(_ editable: Bool) I am looking forward to fully switch to SwiftUI therefore whenever I encounter something that I could do in Obj-c/Cocoa but not in SwiftUI I will evaluate and suggest it as an addition. Thanks!
2
0
294
Jun ’24
Force accessible Color
Looking at Apple's Color Guidelines and taking into account that building my app to work for both light/dark modes I run into an issue where I want to use colors for statuses: red and green. I want to avoid declaring custom colors and I try to use the default ones that adjust for the selected appearance. Unfortunately I noticed that the Color.green does not work well on the default light background of my view (.background(Color (.windowBackgroundColor))) because there is not enough contrast. I noticed that Apple also lists "Accessible" versions of those colors but these are probably managed dynamically. My question: Is there a way to programatically force my app to use the accessible version of a Color (e.g. green)? Thanks
1
0
449
Jun ’24
Title Bar Height Impact on Window Size in SwiftUI on macOS
In a SwiftUI macOS application, when removing the title bar by setting window.titleVisibility to .hidden and window.titlebarAppearsTransparent to true, the title bar space is still accounted for in the window height. This results in a delta (red area) in the height of the window that cannot be ignored by usual SwiftUI view modifiers like .edgesIgnoringSafeArea(.top). My actual view is the blue area. I want to have the view starting in the top safeArea and the window to be the exact size of my view. I am struggling to achieve this. I have also tried with window.styleMask.insert(.fullSizeContentView) to no effect. Can I get some help? 🙂 Here is my source code to reproduce this behavior: windowApp.swift @main struct windowApp: App { @NSApplicationDelegateAdaptor private var appDelegate: AppDelegate var body: some Scene { WindowGroup { ContentView() .edgesIgnoringSafeArea(.top) .background(.red) .border(.red) } } } class AppDelegate: NSObject, NSApplicationDelegate { func applicationDidFinishLaunching(_ notification: Notification) { if let window = NSApplication.shared.windows.first { window.titleVisibility = .hidden window.titlebarAppearsTransparent = true window.styleMask.insert(.fullSizeContentView) } } } ContentView.swift import SwiftUI struct ContentView: View { var body: some View { VStack { Image(systemName: "globe") .imageScale(.large) .foregroundStyle(.tint) Text("Hello, world!") } .frame(minWidth: 400, minHeight: 200) .background(.blue) } }
0
1
411
Jun ’24
Issue with State Persistence in Swift Testing @Suite
Hello everyone, I’m encountering an issue with my Swift Testing suite where state changes made in one test method do not persist to another. I am using Swift’s @Suite and @Test annotations to group and serialize my tests, but it seems that the state is not being carried over between the tests. The second function fails with: Expectation failed: (string → nil) != nil Here is my example code: import Testing @Suite(.serialized) struct createCheckTests { var value = 25 var string: String? = nil @Test("Create string") mutating func stringCreation() { #expect(value > 0) string = "Value is: \(value)" } @Test("Check string") func stringCheck() { #expect(string != nil, "The string is nil") print("\(String(describing: string))") } } What is the correct way to approach such a scenario where I want to test two functions that are related, one to generate some value and one to check that generated value against it initial value using Suites to group and isolate them from other tests? Thanks.
2
0
629
Jun ’24
Xcode Template icon color matching default ones
I want to create a Project Template with an icon that matches the default Xcode templates. I created a vector example icon and saved it as TemplateIcon.svg and it gets displayed for my .xcodetemplate. I would like it to blend in with Apple's default icons (which I know are assets contained inside Xcode bundles). I have tried with fill="currentColor" in my svg xml but it doesn't work. I couldn't find any technical documentation about this. It would be great to know how to design an icon that gets dynamically tinted by Xcode like the default ones. Thanks 🙂
0
0
393
Jun ’24
Define Custom Tests in Xcode project template
I am using a custom app project template and I would like to also include custom Test files (or implementation) when I select to add Swift Testing or XCTest. What should I add to my TemplateInfo.plist to either extend or override the default templates? This is not documented by Apple and it's hard to figure out. Thanks in advance for any help.
0
0
247
Jun ’24