The Swift Den

TSD

The Swift Den

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

Join Server

Community questions

Ssammydoesrobo9/19/2023

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
HHomd9/17/2023

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.

```swift
Picker("Game", selection: $selectedGame) {
Text("No Game Selected").tag(0 as Int?)
Section{
TextField("Search Here", text: $gv.searchTerm).onChange(of: gv.searchTerm) { newValue in
print("On Change Triggered")
searchTimer?.inv...
Pp01nter9/16/2023

Error on one struct but not on the other

Why the difference between Person1 and Person2?
Aaryanrawat_9/16/2023

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
Ttimklose9/16/2023

Offset very strange

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

i have following code

```swift
var body: some View {
VStack {
CameraView()
}
...

override public func viewDidLoad() {
super.viewDidLoad()

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

Assigning propertyWrapper

Hi, I am learning propertyWrappers in Swift last days and I found something strange on the internet. In this article https://nshipster.com/propertywrapper/

import Foundation

@propertyWrapper
struct CaseInsensitive<Value: StringProtocol> {
var wrappedValue: Value
}

extension CaseInsensitive: Comparable {
private func compare(_ other: CaseInsensitive) -> ComparisonResult {
wrappedValue.caseInsensitiveCompare(other.wrappedValue)
}

static func == (lhs: CaseInsensitive, r...
Pp01nter9/13/2023

For??

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) { )
Jj0rdan10989/9/2023

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
Hhippietrail9/9/2023

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

```swift
import Foundation

func fetchData() async throws -> Data {
let url = URL(string: "https://gist.github.com/khaykov/a6105154becce4c0530da38e723c2330/raw/41ab415ac41c93a198f7da5b47d604956157c5c3/gistfile1.txt")!

var request = URLRequest(url: url)

let (data, _) = try await URLSession.shared.data(for: request)
return data
}

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

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...
Yyohann.9/7/2023

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
Ddarshangummadi9/5/2023

AR Measurement app using RealityKit

#swift-development
Value of type - 'ARViewContainer' has no member 'parentSession'
can anyone please help me with the error in the image
Iiwontchill9/4/2023

How to Rename a Project/App in Xcode

I'm not sure what's the best way in doing this. 👀
Jj0rdan10989/3/2023

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🙏
Hhippietrail8/30/2023

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
//
// Search_MenuApp.swift
// Search Menu
//
// Created by Andrew Dunbar on 30/8/2023.
//

import SwiftUI

@main
struct MenuTestApp: App {
@State private var textfieldValue: String = "the text field value"...
Hhippietrail8/27/2023

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...
Iiwontchill8/27/2023

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

struct IntroductionView: View {

@State private var showSplashScreen = true

var body: some View {
if showSplashScreen {
SplashScreenView(showSplashScreen: $showSplashScreen)
} else {
We...
Wwminor8/26/2023

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
safeAreaInsets.top is just 32

I take the maximum of the menu bar...