Questions tagged [swift]

Swift is a general-purpose programming language developed by Apple Inc first released in 2014 for its platforms and Linux. Swift is open-source. Use the tag only for questions about language features or requiring code in Swift. Use the tags [ios], [ipados], [macos], [watch-os], [tvos], [swiftui], [cocoa-touch], and [cocoa] for (language-agnostic) questions about the platforms or frameworks.

Filter by
Sorted by
Tagged with
0 votes
0 answers
5 views

Switching an underline from a selected segment to another

I'm having trouble finding a way to make it go from under one to another. This is the closest I got to it working but still it only works when I first click on the wishlist part first, and then when I ...
0 votes
0 answers
6 views

Moving between NavigationStacks(path:...) throwing "Update NavigationAuthority bound path tried to update multiple times per frame."

I have a segmented picker on my main page allowing the user to select between views to be loaded into that main view. Each of those views has a NavigationStack with a path. Moving between them results ...
-1 votes
0 answers
15 views

Double to String to UILabel [closed]

I have Double = 0.000009 I need to display exactly that Double value in UIlabel, for example "0.000009". String(0.000009) -> "9e-06" or String(0.00001) -> "1e-05" ...
  • 9
0 votes
0 answers
13 views

Where to await to avoid race conditions and not block the Main thread?

I have recently started using async/await (in an existing, Non Swift-UI codebase). Two things that I haven't been able to get an answer to (neither by reading nor experimenting) is whether its wrong ...
  • 3,184
0 votes
0 answers
13 views

Creating Custom Callout for MKClusterAnnotations

I am looking to make it so that every annotation in a clusterannotation when clicked on by the user will display each annotations title and a detailDisclosure button for each respective annotation ...
-1 votes
1 answer
13 views

Expandable Collapse TableView fix row to top

I have expandable-collapse tableView. I can fix row to top when i open it but the problem is when i close the row that opened on the top, it is returning to previous location. I want to keep that row ...
0 votes
1 answer
13 views

How to always show right most part of NSTableView header text?

Let's say I have a NStableView column with ThisIsMyVeryVeryLongName header title. When I reduce the width of column by resizing, it usually shows like this ThisIsMyVery... (showing extra info is on ...
  • 1,994
0 votes
0 answers
10 views

How to extract bounding box coordinates from a YolovV5 object detection model that has been converted to a CoreML model for use in an iOS app?

Here is my coreMl model prediction I need something like that, I need this kind of prediction I have tried it for export !python export.py --weights /content/drive/MyDrive/best.pt --include "...
0 votes
3 answers
34 views

Result values in '? :' expression have mismatching types 'DashboardView' and 'SignInView'

Result values in '? :' expression have mismatching types 'DashboardView' and 'SignInView' i have login interface , when the fields are correctly filled it redirect me to the dashboardView . this is my ...
0 votes
1 answer
13 views

UICollectionView: remove separators for specific cells only

I need to show separators for every cell in UICollectionView except every first cell of a section. I'm using list layout. So far I have only been able to remove all separators using configuration....
0 votes
0 answers
7 views

Change sampleRate and frameLength of audio wav file. From Flutter to Swift

I record an audio input in flutter and need it with different sample rate and a specific frame length in Swift. I record an audio file with record like: await record.start( encoder: AudioEncoder....
  • 41
0 votes
3 answers
40 views

How can I make a SwiftUI View observe changes in a computed property that's an array?

In a SwiftUI App using Core Data, and I have a FetchRequest in the top level View: @FetchRequest(fetchRequest: Student.fetchRequest()) private var students: FetchedResults<Student> And ...
  • 5,578
0 votes
0 answers
6 views

CXCallDirectoryProvider block phone Number

CXCallDirectoryProvider I block a number when that number call he can not reach me everything is ok.But next time that number calls it is already not in block list and he can call me.How to fix it . ...
0 votes
1 answer
12 views

Can we create push notification for Flutter iOS application when app is terminated?

I am developing one application using Flutter and our main targetted platform is iOS. Here, we are implementing notification features using FCM Data messages. We can get notifications while app is in ...
-2 votes
1 answer
48 views

How to sort array of dictionary if 2 key values are same in ios swift [closed]

I am beginner and i want to sort the Array of dictionary if 2 key values are same. Below is the sample data. let arrData: [[String: Any]] = [ ["CategoryCode": "10", "code&...
0 votes
3 answers
24 views

How to select and deselect multiple tableview cells in swift

I need to select multiple tableview cells and if i click that again then it should deselect. so tried below code but got error How to append selected rows arrSelectedRowsBuy and when tap again then ...
0 votes
0 answers
28 views

Scale UIView elements

I have a UIScrollView and I draw a line and a string in it's contentView of type DrawView. I want to maintain the width of the drawn elements relative to the zoomScale. Below is my code. class ...
  • 3,432
-1 votes
0 answers
9 views

Unity Build for iOS cannot find the .../Plugins/iOS/UnityAdvertisement.swift

I'm trying to build my game for iOS. When I open the built project in Xcode and trying to run it on my iPhone I get the build error saying: error build: Build input file cannot be found: '/Users/...
  • 344
0 votes
2 answers
45 views

swiftUI Xcode can't find image in assets

I'm playing around with SwiftUI, I could display an Image from the asset in my Home page but when I try to call it for a model of some french company I can't ... import SwiftUI struct Company: ...
0 votes
1 answer
29 views

Proper cancellation of Tasks in View Model

When using MVVM architecture in Swift for iOS (or for KMM iOS part), is it needed to cancel the Tasks inside of View Model manually or will the iOS do that automatically? If I need to do it manually, ...
-2 votes
0 answers
45 views

Downloading shopItems from JSON with images(url)

Im trying to download items from server as JSON, every item has a link(URL) for it's image. made edits to (reload data after fetching) and still it doesnt work as expected. public class ShopModel: ...
0 votes
0 answers
21 views

Object Marked with Unavailable Attribute Still Shows API Availability Error for Higher Deployment Target

As an example, I'll be using a LazyVStrack, which is available for iOS 14.0, macOS 11.0, tvOS 14.0, and watchOS 7.0. I want to create a view, that has the same API level, but is only exposed to iOS: @...
  • 87
1 vote
1 answer
33 views

Swift - Sink doesn't receive newly published values

I am trying to create a simple Combine pattern in Swift that involves downloading data from URL (Async call) and informs the other class once the download has been completed. The following is a ...
-1 votes
1 answer
37 views

how to activate timer in background ios swift

I started a timer and I ran a functionality to do some task after 5 minutes timer is over, but my app went into background the timer stopped and code not executed. here is my code func startTimerr() ...
-1 votes
0 answers
35 views

SwiftUI Filter nested lists

consider this list: Food and Beverage - Dairy Products - - Milk - - Cheese - - Yogurt - Beverages - - Carbonated Drinks - - Juices - - Tea and Coffee Electronics - Computers - - Laptops - - Desktops -...
  • 308
0 votes
0 answers
27 views

Is it unnecessary to switch to the @MainActor from a function where a helper function is the one actually updating the UI?

In WWDC21's Swift Concurrency: Behind the Scenes video, toward the end of the video they introduce the Main Actor. The main actor is an abstraction of the Main Thread, which means work done on the ...
  • 1,024
2 votes
4 answers
85 views

memcpy to copy array with offset

I have a huge array that I want to copy only a middle portion of it. I'm trying to use memcpy for the performance, but can't figure out a way to do so. Below is an example. How do we provide an offset ...
1 vote
2 answers
44 views

How to build and call a function inside onAppear modifier when we want to implement inside it a for with stride in order to show SFSymbols in SwiftUI

I have implemented in SwiftUI the following code: import SwiftUI struct onAppearmodifier: View { @State var mytext: String = "Start" let symbols: [String] = ["globe&...
0 votes
1 answer
36 views

SwiftUI how to combine From Section with LazyVGrid?

Let say I have a table of texts with different lengths let data = [("aaa","bbb","ccc"),("aaaaaaa","bb","ccccc"),("a","bbbbbb&...
  • 5,775
0 votes
0 answers
12 views

Call async JavaScript function in WKWebView from Swift

I am trying to call a JavaScript function inside the page of a WKWebView from Swift using callAsyncJavaScript, however it claims the function does not exist. Error Domain=WKErrorDomain Code=4 "A ...
-2 votes
0 answers
17 views

What are the best practices when using singletons? e.g URLSession.shared [closed]

I know if we have implemented a thread safe singleton, then doing too many writes from multiple threads can be slow. So wanted to know what are the best practices when using a singleton which has ...
0 votes
0 answers
12 views

Interpolate between data points in iOS Charts

I am using the Swift iOS Charts Library (https://github.com/danielgindi/Charts) to draw a line chart (Cubic Bezier) between a set of data points. My line chart uses time values (timeSince1970) for ...
  • 279
0 votes
0 answers
6 views

Is there a way to reset the buffer in SFSpeechAudioBufferRecognitionRequest?

I have the following record function func record(sketchVM: SketchViewModel, isRecording: Binding<Bool>) { // MARK: 1. Create a recognizer. guard let recognizer = SFSpeechRecognizer(), ...
  • 15.3k
-1 votes
0 answers
21 views

How can I define a NSMenuItem without having to define a keyEquivalent for it?

Currently I am using this code for defining my NSMenuItem: let showWindow1 = NSMenuItem(title: "Show Window 1", action: #selector(showWindow1), keyEquivalent: "1") This code works ...
0 votes
2 answers
35 views

CocoaPods dependency require a higher minimum deployment target

How to find out which iOS version you need to set when you see such a message I can do it manually, step by step increasing the target version. But i think there should be an easier way
  • 19
0 votes
0 answers
10 views

AVCaptureVideoPreviewLayer works on second launch but not first

I have an app that brings up a camera preview immediately when launched. On first launch, the app shows no preview. However, the little green “system privacy” light comes on, and if I try to capture ...
  • 135
0 votes
0 answers
31 views

Code execution order in Firebase realtime database snapshot

I'm trying to retrieve the salary data from realtime database and calculate the "smallnumber" by comparing "salary" with test number 9500. With the for...in loop, I expect to get ...
0 votes
1 answer
46 views

Selectively hiding subviews in swiftui

I would like to make a view that receives its Content as a viewBuilder, like normal, and then selectively displays only one of the child views so provided, hiding the rest. Something like what TabView ...
  • 7,375
0 votes
0 answers
12 views

Apple Metal lineStrip how to draw thicker lines

I am developing an iOS application using XCode 14.2, and my deployment target is iOS 16.2. I have a list of X,Y, and Z values that I want to draw with Metal using lineSrip. This works, however the ...
  • 1,674
0 votes
3 answers
47 views

label gets cropped in horizontal collection view swift

So all I need is to make a horizontal list of just labels and for this I used a collection view. it looks like it works as expected but my label gets cropped and only half the label shows just like ...
  • 253
-1 votes
0 answers
23 views

Flutter/Swift [Int16] to audio File

I listen to a stream in Swift. I get many audio "files" as [Int16]. I need to use them in Flutter. How do I merge the many [Int16] together to one? How do I convert them ALL to ONE mp3 ...
  • 41
0 votes
1 answer
19 views

How to run a different storyboard (other than main)?

I have created a new storyboard. I don't want to connect it with main right now but want to execute it in the simulator. However, every time I create the build only the main storyboard is executed.
  • 141
0 votes
0 answers
20 views

RevenueCat SDK 4.17.8: Correct way to @Publish up-to-date subscription status in SwiftUI using Swift concurrency

I have an existing RevenueCat implementation in SwiftUI using the Purchases SDK 3.14.1 in production. I am currently in the process of upgrading to the latest RevenueCat SDK 4.17.8 and am therefore ...
  • 91
0 votes
0 answers
7 views

Can't upgrade Facebook IOS SDK to the latest version

When I follow the installation instructions here I get version 9.3.0 of the SDK. But when you check the SDK's repo page here, the latest version is v16.0.0. For some reason, even though I am selecting ...
  • 119
0 votes
0 answers
26 views

Context menu is not working properly when in VStack that's in a List in SwiftUI

First, I'd like to emphasize that with a ScrollView instead of List, this issue doesn't happen. I have created this test code: import SwiftUI struct ContentView: View { var body: some View { ...
  • 1,802
0 votes
0 answers
15 views

AppIntent to get Details for AppEntity like eg. Weather

I have an Intent, that returns an AppEntity with data from my App. Now I would like to build an Intent to get the data from all properties of the AppEntity from the first Intent. This should work like ...
  • 1,278
-1 votes
0 answers
15 views

IBInspectable stored property in extension

I would like all subclasses of UIView to have a stored property IBInspectable. Unfortunately I can't use an extension of UIView, because in an extension, an IBInspectable cannot be a stored property. ...
1 vote
0 answers
24 views

UIView animation downscale instantly hides the view

I'm trying to downscale a view like this : func test() { UIView.animate(withDuration: 2) { self.testView.transform = CGAffineTransform(scaleX: 1, y: 0) } } When I do this the view ...
  • 7,684
0 votes
1 answer
24 views

snapshot doesnt show until i close the app on the simulator xcode firebase

Problem: Im trying to grap data from firebase realtime db and use it in my ios app, I am trying to access the value with a snapshot, but when I run the simulator, and I try adding a value in firebase ...
  • 1
0 votes
1 answer
49 views

How to give a blue style to a NSButton without having to set a keyEquivalent for it?

I am using this code below for my NSButton, for having the blue style Button. But this code make my Button react to return key on keyboard, which it is not my wish, my goal is having this style ...

1
2 3 4 5
6517