Collect all kinds of swift programming exceptions and fault solutions.


SwiftUI ForEach understanding variable usage

The following code does work for me...
VStack {
ForEach(0..<self.rows, id: \.self) { row in
HStack {
ForEach(0..<self.columns, id: \.self) { column in
...


Command MergeSwiftModule failed with a nonzero exit code

I'm getting an error when I try to build my MacOS app in Xcode.
Command MergeSwiftModule failed with a nonzero exit code.
error: umbrella for module 'PDFKit' already covers this directory


In SwiftUI, How do I increase the height of a button?

As you can see in the screenshot, the button height does not adjust to fit the text size, making it look ugly. How can I increase the hight of the buttons, so it does not look stupid. My question i...


Layout Constraint Errors with simple UIToolar for keyboard inputAccessoryView

I was getting a lot of layout constraint errors so I created a new project and simply have a UIToolbar and a UITextField to try and troubleshoot the problem. Even with a clean project, I still get


I tried to set up swift editing vim with sourcekit-lsp but vim-lsp keep saying sourcekit-lsp is not installed

I began to study swift with macbook pro 13 few weeks ago.
I really enjoy developing with xcode but I want to try with vim.
So I installed xcode 11.4 beta which includes toolchain in it.
and I clone


Swift: ReadMoreTextView Library Tap Detection

Hello I'm currently using the open-source ReadMoreTextView library to expand my description. How do I go about detecting only when "Read More" or "...Read Less" is tapped. Currently when using these


Programmatically creating AVPlayer results in constant CUICatalog warnings

I'm showing video in a collection view cell of an IGListKit powered list.
This is the cell:
import AVKit
class ContentCell: UICollectionViewCell {
static var vc: UIViewController?
func setup...


How to crop a video recorded given by AVCaptureMovieFileOutput?

I've made CustomCamera which records video into full screen (by setting AVCaptureVideoPreviewLayer's videoGravity to resizeAspectFill) and saving the recording using AVCaptureMovieFileOutput. The


Xcode 11.6 crashing when running test - missing library

I am trying to run some XCTest. I am not very familiar with it already. I imported my main module to test some classes. I had to open xcworkspace, instead of xcodeproj and then it compiled.
However...


Saving data locally (IOS)

How would I be able to store data that is added into a tableView that I would be able to access and delete after the app is closed and loaded again?
My app basically has a contact section that you ...


How to show sheet view after last item finished playing in AVQueuePlayer?

I am playing an array of videos using AVQueuePlayer, but after the last video I see AVQueuePlayer trying to play the next video when there isn't any left. And what I'm trying to do is to toggle a b...


Core Data not getting saved when presented as a card

I'm learning core data so my knowledge is limited. I have an app where I'm trying to store weight lifting data and then list it out. I have two views one view to add data and one view to list the...


Print indexpath row on label in each table view cell

In my swift code below each table view cell features a label. In that label I want to print the index path row. So in cell one the label should be 1 in cell to it should read 2. I tried to code ...


UIView IBOutlet not changing when change called from a different class

I have an XIB with a UILabel to it. I have referenced the UILabel to a UIView class that I have created. I can change the label using label.text = "hi" when initializing the view. When I ...


End task code for my toggle switch in Swift

I am trying to figure out an end task call. basically what the switch needs to do is populate data from a geojson file on the, when the toggle is on and unpopulate when the toggle is turned off. so...


How to bridge a Swift Promise to React Native

I'm integrating an iOS native SDK into React-Native. There's a function called SDK.getCardData which I want to use from RN. My first attempt was to call resolve and reject inside the closure:
import


How to select buttons from 10 options in swiftUI?

I have 10 different button options. When I select one or two specific options, which are tap9 and tap10 in my case, I want to disable the other 8 options and enable another button which is "N...


Updating the selected object in a SwiftUI List

When using a List is SwiftUI, I have code to update the selected object which works fine. However the change to the selected object is not reflected in the List until the selected object changes.
H...


WKWebView turns black when "Open Link" pressed after long press a link

I'm programming in swift and run into an error that my WKWebView turns black after "open link" or "add to photos" in safari.
So I got my WebView and everything works fine. But w...


Error trying to generate a random key pair when unit testing on a real device iOS Swift

When i try to run my unit test on a real device it fails.
The returned error is
-25293 ("The user name or passphrase you entered is not correct.").
Here is my failing code:
let accessCo...


Fill circle with wave animation in SwiftUI

I have created a circle in swiftUI, and I want to fill it with sine wave animation for the water wave effect/animation. I wanted to fill it with a similar look:
Below is my code:
import SwiftUI
s...


Struggling to pass data to UI - Swift

Good day, I'm trying to pass data to my Profile UI View.
This is my Customer Class:
class Customer {
// Creating a customer
let name: String
let surname: String
let contactNo: Strin...


How to tell Swift which function signature to use between default optionals

I want to instantiate the root view controller of a Storyboard I created.
To do so I was used to call -instantiateInitialViewController() from a storyboard.
The thing is since iOS13 there’s a new m...


UI Testing: How to query for picker value in a form

I'm trying to write a UI test for a form containing a picker. I would like to check whether the selected value of the picker is "2" or "2 Coins" respectively after launching the...


SwiftUI TextEditor, exception during undo with navigation change

My application uses a number of TextEditors which are bound to practices in my data model. A navigation pane changes the practices that are viewed. Undo is implemented in my data model, like this:
...


Explaination to tag issue in UITapGestureRecognizer

This is not a massive issue with me, I am just struggling to understand what is happening. Other rather how to make it work the way I want it to work.
Consider the following code of any standard


Update cell content - UITableView Diffable DataSource

so I'm implementing the Diffable Data Source API for a UITableView, I have a trailing swipe action mark as favorite the item that you swiped; what is the correct approach using this API, re-render my


Binary operator '==' cannot be applied to operands of type 'Bool' and 'String?' for Swift in 2020

I can't seem to figure out why the equal operator won't work. Please help.
Here's my code:
@IBAction func LoginButton(_ sender: UIButton) {
let Username = UsernameTextField.text;
let Pass...


how do i fix Type '()' cannot conform to 'View'; only struct/enum/class types can conform to protocols

hi i'm making a game but i can't get an if state to work
now i added the full code of the program (contentView.swift)
hope its more useful to help me
the code is made in xcode and the program is for


SwiftUI - how to get storyboard launch screen image exactly same as SwiftUI background image

The background of my app is a full screen image set to .scaledToFill. For some reason when I use the same image as the launch screen image, it has two differences:
The color saturation seems diffe...


How can I save variables with first start in swift?

im programming a soccer Live-Ticker and want the user to select a team on first start.
How can I handle this? Can you name me something so I can google for it?
I could use super.viewDidLoad() and


Firebase - How to see the values for the "Product revenue" and "Average price" of the "Top products" report?

I'm having trouble when working with the add_to_cart event as I'm not able to see the values for both the "Product revenue" and "Average price" columns of the "Top products...


Swift struct performing 10x faster as a parameter than a local variable

I have made some modifications to this proof of concept code that compares struct and class performance and found that the code is 10x slower for structs when I make a simple change to pass


Apple Search Ads Events Not Tracking in Firebase

I'm trying to track Apple Search Ads campaign name, keywords etc. by saving it as user property values in Firebase. I setup Firebase attribution events tracking as mentioned in documentation below:...


SwiftUI: Changing variables in ContentView from functions inside AppDelegate

So I have a register for push notifications function in AppDelegate.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var toggler: Toggler?
func application(_ application:


How to create custom sound in FCM for iOS? (FCM custom sound reverted to default sound in iOS)

My custom sounds for remote notifications suddenly stopped working today. They worked yesterday and played fine. Then today, out of the blue, they stopped working. I did not update any code or make...


Text is centering in view instead of trailing the view

Why is the "..." not trailing? it should be on the right of the screen always not the center.
ZStack {
HStack {
Text("Good morning")
.padding(.leading, 2...


Second storyBoard not functioning?

So I am attempting to utilize a second storyboard for my project, as an onboarding screen. When I make the second storyboard I put in the view controllers and I put a button on the initial page for...


How to change background color and image when it's tapped to the button in swift UI?

I want to change background color and add an okay button image to the selection point when I tap to that point. How can I do that ? I do know how to change the background color but I'm not sure how...


How to save transformable attribute to Core Data in Swift

I'm building a SwiftUI app that fetches movie data from TMDB. When the user adds a movie to their watch list, I'm trying to save the data as a Transformable attribute in Core Data.
The problem is t...


iOS Chart Horizontal Bar Chart not showing bar values

I am using iOS charts (V3.3) to draw a horizontal bar chart for player performance statistics for a sports app. I want the bar value to be shown next to the bar in each case. I can make this happen


How to capture video and audio from another application's window - Swift

How can I capture a video and audio feed from another window on the users Mac, similar to how QuickTime and OBS let you capture a window? I would like to save this feed as an mp4. I have tried using


Show an alert if the entered credentials are wrong in swift

when I input wrong username or password my application got hang
I want to show an alert when input entered is wrong here is how I'm trying
switch response.result {
case .success:
...


Having collectionViewCell.label.text Change Every Second with Timer

I am currently learning to code swift apps and am trying to do some projects on my own. My current personal challenge is to do a countdown timer app. The concept is simple: the user enters a date, ...


Is there a way to call a function once a View Controller leaves the view stack?

ViewDidDisapear and ViewWillDisappear are still called if another View Controller is above the (say, for example, you push a view controller on top of it). Is there a function that is only called o...


How to change multiple labels one at a time? - Swift

I've got 5 labels and for each label im assigning a random value from an array when a button is clicked. Im wanting the first label to be changed then the second and then the third etc... but canno...


Swift enum protocol conformance

I want to create a Swift protocol that my different enums can conform to, so I can use the same 'type' while utilizing the enum's rawValue. Basically, the protocol should look like this:
protocol


How to make UITextView wrap its content (NOT dynamically)

I keep seeing answers about resizing a UITextView dynamically after text changed. I don't need that; i just have static text and want to specify in the storyboard that the height should match the t...


Filter nested objects in coredata using NSPredicate SUBQUERY

My Data Model as follow, and my objective is to filter the Contacts belong to that Community
Contact<<->Account<<->Comunity
This is what i have done so far and im gettin is excep...


How to stop autofilling address in textfields in swift?

I have added three permissions in info.plist
and popup coming with three options.. here
1)if i click "allow while using app" then i need to autofill textfields with current location addre...


Next