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

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.

MusicKit systemMusicPlayer.nowPlayingItem always nil?

I've already made sure to add the privacy requirements to Info.plist and have checked my phone's settings to ensure that the app has access to Media and Music libraries. Anyone have any experience solving this?...

I need help :(

Hello, I'm new to Swift and I have a problem. When I press the button it is supposed to show a search bar which contains a list but from "ContainView" it shows me nothing
No description

Clipped and small List in Sidebar

Hello, all. I made a SplitView with a List in the sidebar, but the List is TINY in the sidebar for some reason (see attached image). Why is the List not taking up the full size of the sidebar area? Why is it so small? Thank you! ``` struct ContentView: View { let assets = Assets(textures: [.init(id: "ColorMap", width: 1024, height: 1024, format: "png")]) ...
No description

Metered Paywall in SwiftUI

I am trying to implement a metered paywall in SwiftUI with the help of StoreKit How can I do that? Any suggestion?...

WWDC 23 Object Capture Framework Error

Hi, was wondering if anyone had tried running the object capture code from the previous WWDC event from "https://developer.apple.com/videos/play/wwdc2023/10191/#:~:text=To%20capture%20all%20the%20details,your%20object%20from%20all%20angles." I tried but keep running into a framework linking error during runtime, dyld[1164]: Symbol not found: _$s21DeveloperToolsSupport15PreviewRegistryPAAE7previewAA0D0VvgZ Referenced from: <9D4B3941-AF10-3958-8EAD-5BB02CC40CA2> /private/var/containers/Bundle/Application/CDF2A484-0A6B-49D4-B6D2-061EA4124AAB/ObjectCapture.app/ObjectCapture Expected in: <0BD6AC59-17BF-3B07-8C7F-6D9D25E0F3AD> /System/Library/Frameworks/DeveloperToolsSupport.framework/DeveloperToolsSupport. SETUP: ...
No description

Cordova ios plugin in swift (FFmpeg)

Guys, So I have to add ffmpeg to my cordova plugin project as for android part was easy and done. Now I have two problems, First, how do I really add it to my project in plugin.xml as using framrwork with podspec shows error and as deprecated. ...

BottomSheet Problems

I am working on a bottom sheet for my code using the built in functionality of .sheet. Is there a way for you to disable the initial animation where it comes from the bottom and just have appear on screen when you open up the view. The video I have attached in the description better highlights my question. When I open up the view, there is a second or so delay before you see the bottomsheet, I want the sheet to appear instantly when i open up the view and when I hit the back arrow, I want the bottomsheet to disappear. @State public var isSheetPresented = true...

Custom Label and OOP

I added a photo as an example of "how we can initialize and assign properties" so I wonder If can do the same thing for Labels to assign their value by myself?...
No description

I'm having a stroke with CGEvents and simulated input - please help

Anyone here happened to mess with the Quartz Event Services API ? I'm having a hard time trying to simulate input to a particular app. My goal is to achieve a simulated click input at any coordinates in a target app's window, if possible even if it is in the background (not foremost). The purpose of this is to have an automated custom routine running on an app in the background without hindering mouse movements and clicks. ...

NavigationStack with path initializer giving me "No exact matches in call to initializer "

My code: ```swift struct ListView: View { @State private var presentedViews: [DayView] = [DayView(date: "March 23")] ...

market demand/supply

Is there more demand for swift developers and not as much supply? I’m a web dev with mainly MERN trying to make myself more competitive in the market so I was thinking native iOS is a good route anyone here in the field and have first hand experience with hiring practices etc?...