The Swift Den

TSD

The Swift Den

The Discord server for Swift developers. Get tips and snippets for your projects!

Join

swift-development

javascript

python

rust

c-sharp

opensource / full version paddle alternative opensource?

Hi everyone im building a swift ui app with a free version and an upgraded features for a small payment. Is there anywhere in the xcode swiftui world For licensing software with a femote api like paddle does? ...

Is it possible to replicate Mac's standard Help menu Search item?

Old programmer but Apple programming noob. I wanted to make a menubar-only app that had a text entry field in its submenu, just like Help/Search. It compiles with no errors and runs with no errors and no log output but the TextField between the "Buttons" dosn't appear. ```swift...
No description

How to position vertical Slider

I'm an old programmer but new to Mac and SwiftUI. I'm trying to get a vertical Slider positioned right up against the right edge of the window. Apparently this requires rotation:
Slider(value: $vx).rotationEffect(.degrees(v1))
Slider(value: $vx).rotationEffect(.degrees(v1))
But this rotation is just an effect. All measurements, bounding boxes, alignment, etc that effect its size and position behave as though it's still horizontal, which makes it incredibly unintuitive and frustrating to reason about, especially when new and unfamiliar with how positioning etc is done even for normal UI elements....

View Changing in Simulator not Preview

I've noticed that these lines of code, whenever I run them in the simulator, it would preview the changes in view. However, whenever I run them in the Xcode preview, it wouldn't change the view at all? I'm quite confused about this. ```swift import SwiftUI ...

NSScreen visibleFrame / safeAreaInsets not adding up right?

I'm trying to compare visibleFrame and frame to figure out whether the dock is currently showing on a given screen. Of course, I need to account for the menubar and any inset caused by a macbook notch as part of this. However, the number I'm getting don't quite add up right! For example, on my M2 Macbook Air: frame has a height of 956 (as expected) visibleFrame has a height of 919...

SideMenuView help please, I don't have long

I have a completely fine SideMenuView and no errors but nothing comes up on the app preview, I will probably send a the code and that tomorrow

Changing a Boolean when a key is pressed.

Does anyone know how I would be able to change a Boolean when a key is pressed on a keyboard?

AngularGradient issue

Hello! I'm trying to replicate a 4 point gradient you see on the left, but I'm getting this weird line that doesn't let black and red connect and it looks like that colors do not start from corners, but are a bit off. Any help is appreciated ```swift AngularGradient( gradient: Gradient(colors: [.black, .black, .white, .red]), ...
No description

MacOS user-level custom FAT16 USB volume

There's a slightly tweaked FAT16 implementation used on some Akai samplers. I've created an emulator of one of those samplers. It supports r/w USB volumes with a custom FAT16 implementation. All of this works, but currently goes via the deprecated AuthorizationExecuteWithPrivileges for achieving raw USB volume access. Yesterday I looked into migrating to SMJobBless, but it also turns out to be deprecated. It's an incredible amount of work, and this SMJobBless example gave the same error as the "Hello job bless" I tried adding directly to my project, which is "Error Domain=CFErrorDomainLaunchd Code=4". Then I looked into using FUSE, but from what I understand, opening a raw USB volume still requires the user-level process to be elevated. Is this correct?...

Can someone please send code for a side menu view?

I just saw it in a forum here and am curious and it sounds like a fun interesting challenge, please tell me how and I will experiment and adapt

Buttons not working on SideMenuView

Hello good morning. I am trying to make an application and in the homescreen I have a SideBar and inside several buttons. I can not get the buttons to work. Also I get this error in console when I run it "NavigationLink presenting a value must appear inside a NavigationStack or NavigationSplitView. Link will be disabled." but I can't solve the error. ...

Nondescript crash in my SwiftData app when trying to access a dictionary

I'm making an app for a school project in SwiftUI and SwiftData. It's a habit tracker and I have a SwiftData class for persisting basic habits. Where the problem started is that I'm trying to implement a way to track when a certain habit was completed. I deleted my existing instances of the class and added a dictionary under self.isCompleted as [Date:Bool] (so 3rd of August = true etc.)...

button not working n00b help pls

hiii i’m working on cloning an app so i can get more use to swift (i’m a student). so i have a view with a button that opens another view in a sheet presentation. from that sheet i want to add another button that goes to another view. so first view button -> sheet button -> last view but the second button is not working. i basically copied the code from the first button since it worked and presented the view i wanted. but the button doesnt work and won’t even print when tapped. ...
No description

What Swift language feature to achieve SwiftUI's `$` to return `Binding<Value>`?

Hi. I'm new to Swift language and little knowledge about the history of it. I'm curious which language feature to make it happen, like property wrapper is used to make @State works. Note this is not the question how I use $ to return bindings....

help please

I have a sorted array and timer, I just need help to get images to show up at the top or bottom of the screen when the timer runs out, please help me, ping for code

Issue Displaying Charts with CustomView

Hello! I'm trying to display some 6 different charts on my MacOs application, but i'm struggling setting this up. I have a 'ChartsViewsController.swift' file in which I have those variables : ``` // Arrays to store the acceleration and angular rate data for each axis typealias Model = (dataValue: Double, time: String)...

SwiftData and Canvas Previews confusion

Has anyone gotten the SwiftData, SwiftUI, and Live Canvas Preview features to work in conjunction with each other? I can get the previews working if I don't use SwiftData, but when I try to have a view that uses SwiftData, Xcode seems to error out at times for non-obvious reasons, and I'm not sure if there's a recommended way to fix those problems. I've been trying this approach with limited success: https://stackoverflow.com/questions/76543560/how-to-preload-data-into-swiftdata-model as sometimes my data model classes (which have @Relationships to other models) end up causing Xcode errors....

I can’t seem to figure out to make my application compatible in landscape mode/for iPad

Hello my name is Ethan, and I’m just learning swift, I am having issues trying smoothly transition into landscape view. Would anyone be up to run through the view controller with me and help help me learn how to orientate and properly resize my application for iPad?

<unknown>:0: error: could not load the swift standard library

Hello, I am trying to get started on swift with windows 10, and I had downloaded the windows development pack and am using VS code. ```swift import Swift ...

WatchConnectivity won't work. Unreachable

The app is installed on both iOS and watchOS, but it won't show session.isReachable = true even after I activate. I've tried what feels like everything including running a number of solutions folks have posted online and on github.