The Swift Den


The Swift Den

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

Join Server

Community questions


Single Line text detection with DataScannerViewController

Anybody know how to use the DataScannerViewController for detecting text line by line? Right now it just detects large blobs of text (each RecognizedItem) but I want to be able to split these detection blobs into multiple lines of detected text. I dont want to use VNTextRequest because detection is more spotty

OnChange() doesn't trigger inside picker navigation view

For some reason the on change that I put on textfield only triggered after I close the selection view.

Picker("Game", selection: $selectedGame) {
Text("No Game Selected").tag(0 as Int?)
TextField("Search Here", text: $gv.searchTerm).onChange(of: gv.searchTerm) { newValue in
print("On Change Triggered")

Error on one struct but not on the other

Why the difference between Person1 and Person2?

Viewing A 360 Degree Images and videos

I am making a app for viewing 360 images and videos using gesture I am unable to find out it how it will be done

Offset very strange

I have a CameraPreview which is displaying very strange on the bottom of the screen

i have following code

var body: some View {
VStack {

override public func viewDidLoad() {

// Set up the video preview view.
previewView.session = session
previewView.videoPreviewLayer.videoGravity = videoGravity
previewView.videoPreviewLayer.connection?.videoOrientation = AVCaptureVideo...

Assigning propertyWrapper

Hi, I am learning propertyWrappers in Swift last days and I found something strange on the internet. In this article

import Foundation

struct CaseInsensitive<Value: StringProtocol> {
var wrappedValue: Value

extension CaseInsensitive: Comparable {
private func compare(_ other: CaseInsensitive) -> ComparisonResult {

static func == (lhs: CaseInsensitive, r...


the for word is throwing me off here, he could've used any other word right? it's not anything syntaxt related?

( the for in func setAge(for person: String, to value: Int) { )

menubar extra swiftui open main window on tray click?

Like title menubar extra swiftui open main window on tray click?

There seem
To be no way to just implement this.

I want to click the tray icon show mail menu or rightclick to show the tray menu appear.

Is this possible or should i ditch swiftui if thrse simple cases are not porroble

Can progress reporting be added to this style of https transfer?

import Foundation

func fetchData() async throws -> Data {
let url = URL(string: "")!

var request = URLRequest(url: url)

let (data, _) = try await request)
return data

struct Main {
static func main() async throws {
do {
let foo = try await fetchData()
let bar = String(data: f...

Can't run Xcode at all

Hi. I'm using a MacBook Air M1, running Xcode Version 15.0 beta 2, on macOS Sonoma 14.0. When running a simple playground code of swift, i get an error: failed to launch proccess. this operation couldn't be complete. StackOverflow claims the solution is to disable Rosetta for xcode by going to the xcode app file, selecting get info and unchecking the Rosetta checkbox. However, I don't have such a box. I tried to run some command someone said and it shows i'm using 2 different architectures as sh...

XCode concern please help

Hello, I am a user on Macbook, and I am looking to make a simple website on XCode, preferably with HTML/CSS/Java but it seems incredibly confusing to do so.

I see that most people use swift on XCode but I was just wondering if there was a way to make a regular html site on Xcode

AR Measurement app using RealityKit

Value of type - 'ARViewContainer' has no member 'parentSession'
can anyone please help me with the error in the image

How to Rename a Project/App in Xcode

I'm not sure what's the best way in doing this. 👀

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?

I would like to implement a trail version
With a remote license api server to validate and unlock the software🙏

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.

// Search_MenuApp.swift
// Search Menu
// Created by Andrew Dunbar on 30/8/2023.

import SwiftUI

struct MenuTestApp: App {
@State private var textfieldValue: String = "the text field value"...

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))

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 unfam...

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.
import SwiftUI

struct IntroductionView: View {

@State private var showSplashScreen = true

var body: some View {
if showSplashScreen {
SplashScreenView(showSplashScreen: $showSplashScreen)
} else {

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
NSApp.mainMenu?.menuBarHeight is 36 is just 32

I take the maximum of the menu bar...