As of May 31, 2023, we have updated our Code of Conduct.

Questions tagged [swift]

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, iPadOS, macOS, watchOS, tvOS, Linux, and z/OS.

Filter by
Sorted by
Tagged with
2 votes
1 answer
69 views

Is Palindrom-function in Swift

Task is simply to write the classic isPalindrom-function. Here's my implementation: ...
michael.zech's user avatar
  • 3,990
4 votes
1 answer
220 views

Function, which checks if all letters in a string are unique

The task is writing a function, which checks if a string contains only unique characters. Means: is each character is included only one time. Here's the solution, I have developed: ...
michael.zech's user avatar
  • 3,990
1 vote
1 answer
54 views

Swift-function, which counts all occurrence of a character within a string

I wrote this function, which (shall) count all occurrences of a specified character within a given string. ...
michael.zech's user avatar
  • 3,990
1 vote
1 answer
63 views

Building a UITableView with fixed number of cells progammatically

I am building this pet project with UIKit. The App's main goal is to keep track of my daily expenses. The AddExpenseViewController is responsible for capturing user ...
motita's user avatar
  • 11
2 votes
0 answers
55 views

Refactoring of this massive ViewController with a UITableView in it

I'm making an application that has a UIViewController with a UITableView in order to show the favorite users that the user of ...
user15675885's user avatar
0 votes
0 answers
29 views

Manage Access Control on Swift UI Elements

I have following ViewController class with a tableView. ...
Tharindu Ketipearachchi's user avatar
0 votes
0 answers
41 views

UIImageView loading from URL with cancellable task and safe to use in a UICollectionView

I am trying to make a UIImageView class / extension that can load an image from a URL. the image view should not get confused with concurrency when scrolling through a UICollectionView and the data ...
Halpo's user avatar
  • 101
2 votes
1 answer
113 views

Swift - efficient array searching

I am trying to find a way to search an Int array (all numbers are > 0) and identify sequences where the sum of each element is a specific number. One element can ...
koen's user avatar
  • 169
0 votes
0 answers
39 views

Greeting Kata in Swift

I've just completed the Greeting Kata and I am hoping for some feedback. Here's the Kata: Requirement 1 Write a method greet(name) that interpolates name in a simple greeting. For example, when name ...
Asif Mujtaba's user avatar
4 votes
1 answer
92 views

Queue implemented using two stacks in Swift

I need your expert opinion! In fact, for a Leetcode Problem, I had to code a queue using 2 stacks. It's shown just below and functions well. It is a pretty simple code with peek, pop, push, etc. ...
Thomas H.'s user avatar
0 votes
0 answers
63 views

Retriable URLSession#dataTask

I am extending URLSession.dataTask to also allow retries, if the request fails. I am particularly interested in the reliability of the code. Speed and efficiency ...
Goga's user avatar
  • 101
3 votes
1 answer
76 views

Finding Highly Composite Numbers in Swift

This code finds highly composite numbers (numbers with more factors than any smaller number) in Swift. I'm not too familiar with Swift, I did this in python but it was too slow so I decided to try it....
Octobass's user avatar
1 vote
1 answer
117 views

MVVM pattern in Swift

I've been coding for some time now and since I am working alone I'm not strict in my coding structure approach(bad idea) and was only focused on getting things done which resulted in MVC(MASSIVE-View-...
Joe 's user avatar
  • 13
1 vote
0 answers
214 views

CoreBluetooth delegate to async stream

I want to use async/await by AsyncStream for Bluetooth scanning. The CoreBluetooth is using the delegate pattern. The following code provides an adapter for using ...
lotusirous's user avatar
0 votes
0 answers
50 views

Better SwiftUi Login implementation

I've just started learning swiftui and I'm creating a basic login screen for now. The UI is set up how I want and the actions just print to console roughly what they will do. I'm struggling with ...
IndexZero's user avatar
3 votes
1 answer
89 views

Exceeded time limit on Trie search with Backtracking using Swift

I have been trying to solve Trie related problems over at leet code and came across this interesting problem 211. Design Add and Search Words Data Structure Here is the question for convenience: 211. ...
Shawn Frank's user avatar
5 votes
2 answers
421 views

Leet Code 139 (Word Break) using a trie with recursion

I was attempting to solve LeetCode 139 - Word Break Given a string s and a dictionary of strings wordDict, return ...
Shawn Frank's user avatar
3 votes
0 answers
147 views

Merge two strictly increasing sequences, without duplicates

This work is motivated by Sum of natural numbers below threshold, where several Swift solutions to Project Euler #1 (with arbitrary upper bound) are provided. One way to think of it is to start with ...
Martin R's user avatar
  • 22.9k
5 votes
3 answers
181 views

Sum of natural numbers below threshold

I have this code: ...
Shum's user avatar
  • 53
2 votes
0 answers
65 views

Function for formatting data retrieved from a battery via Bluetooth Low Energy

I have the following function in Swift and am looking to improve the readability. The function takes from the deviceData object which holds maps of data like ...
Dylon Jaynes's user avatar
1 vote
1 answer
78 views

Using Swift Combine's .map function with external variables

I have a motionManager class which uses CMMotionManager() to send rotationRate and attitude values to a publisher in the form of a MotionValueModel. ...
Bjorn Morrhaye's user avatar
1 vote
1 answer
76 views

API call to list top stories using dependency injection in iOS with MVVM

I'm currently trying to find out what's the best networking architecture for MVVM applications. I couldn't find many resources and decided to go with dependency injection based architecture as per the ...
Tharindu Ketipearachchi's user avatar
1 vote
0 answers
52 views

Idiomatic API Authentication flow with ASWebAuthentication and Combine

I'm working on an app to display statistics based on user data from a third-party service's API. The authentication flow for the service's API that I wrote works, but some parts of it feel a bit ...
Luciano's user avatar
  • 297
2 votes
1 answer
145 views

Trie data structure in Swift lang

This is an implementation of a generic Trie DS, in Swift-lang, that is using however, for the sake of a easy example, strings. It implements two operations, insert and search. So it can insert a text, ...
Dan's user avatar
  • 123
1 vote
0 answers
52 views

Setting constraints to scale app's UI for consistent display across all iOS devices

For apps which don't have significant layout changes between the iPhone and iPad versions, I usually set the constraints of all UI elements (views, labels etc.) as fractions of the current device ...
Quack E. Duck's user avatar
3 votes
1 answer
311 views

UIImage downscale and compression

getFinalImageData(:UIImage) takes a UIImage and downscales its size dimensions (to 400 ...
trndjc's user avatar
  • 133
3 votes
1 answer
120 views

Simplify wordle logic Swift

I wrote logic for "Wordle" game but I think it's too heavy and not very readable. Is there any way to improve it? Simple wordle game with conditions: 1) Green colour - "G" if ...
ofigensky's user avatar
2 votes
1 answer
159 views

SwiftUI/Swift code for changing item values in an immutable struct

just wanted someone to review my code and perhaps simplify it a bit. Everything is working as expected for the moment but it seems too much code for what i'm trying to achieve. Especially the function ...
Bjorn Morrhaye's user avatar
1 vote
1 answer
231 views

Finding the winner of a tic-tac-toe game in Swift

Working on the problem Find Winner on a Tic Tac Toe Game, I took several hours longer than an artificial time constraint the site had for mock interview purposes. This leads me to wonder if my ...
Curious's user avatar
  • 113
1 vote
1 answer
118 views

Checking whether two values are isomorphic in Swift

Working through a book problem Write a function that accepts two values and returns true if they are isomorphic. That is, each part of the value must map to precisely one other, but that might be ...
Jakory's user avatar
  • 23
1 vote
1 answer
167 views

Finding the longest prefix among words in a string separated by spaces (Swift)

Solving the problem Write a function that accepts a string of words with a similar prefix, separated by spaces, and returns the longest substring that prefixes all words. Sample input and output The ...
Jakory's user avatar
  • 23
0 votes
1 answer
52 views

Understanding How To Approach A Permutational Word Search

This question is carried over from StackOverflow... First time posting here, so bear with me. The topic is constructing a search made up of a given string, and a series of letters, where each of the ...
Dan Donaldson's user avatar
2 votes
2 answers
148 views

Create a custom split method that keeps the delimiters in Swift

I have implemented a custom split method that replicates the original functionality of the collection's split method in Swift and keep the delimiters (element separator). After a lot of trial and ...
Leo Dabus's user avatar
  • 155
1 vote
1 answer
267 views

Best way to do Input Validation on Swift/iOS/UIKit

I have the following form that creates a new "activity": For which I want to enforce the following requirements: Name => minimum # of chars: 1; maximum # of chars: 50 Description => ...
Enrique's user avatar
  • 145
1 vote
1 answer
131 views

Bank account concurrency problem Swift

I tried to implement a simple BankAccount class to practice providing a solution to the common Bank Account transaction data race problem. Reference to a description of such a problem can be found ...
emrepun's user avatar
  • 165
2 votes
2 answers
513 views

Blocking call to an async function

While migrating to structured concurrency it may be sometimes convenient to temporarily make a blocking call to an async function - e.g.: ...
Milos's user avatar
  • 609
2 votes
1 answer
150 views

Concurrent Operation subclass combining KVO compliance and thread safety

This is a subclass of Operation that attempts to combine the requirements of KVO compliance and thread safety. Do I have the KVO notifications and thread safety ...
lurning too koad's user avatar
1 vote
1 answer
138 views

Clean way to listen to asynchronous messages

I am currently writing an Engine that runs on a background thread which produces outputs asynchronously. Those outputs are gathered by a Pipe, whith a ...
Olympiloutre's user avatar
1 vote
1 answer
290 views

Optimize Leetcode 239. Sliding Window Maximum using Swift

LeetCode problem 239. Sliding Window Maximum You are given an array of integers nums, there is a sliding window of size k which ...
Shawn Frank's user avatar
1 vote
1 answer
139 views

Minimum Window Substring in Swift exceeds LeetCode runtime check

This is a popular question on LeetCode: 76. Minimum Window Substring Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in ...
Shawn Frank's user avatar
2 votes
1 answer
61 views

Start / stop animating activityIndicatorView for many dataTaskPublishers

I consume a RestApi with few Combine Publishers and want to visually represent ongoing progress with UIActivityIndicatorView. My current logic uses ...
Blazej SLEBODA's user avatar
4 votes
1 answer
2k views

Debounce and throttle tasks using Swift Concurrency

There are many debouncer and throttle implementations created using Grand Central Dispatch, and even one built into Combine. I ...
TruMan1's user avatar
  • 123
1 vote
1 answer
2k views

Changing the color of some pixels in an image in Swift

My code is working perfectly fine, except for one-thing. The performance is not up-to the mark. What I am trying to achieve is I have an image with a few circles (each circle has a border with ...
Raja Saad's user avatar
  • 113
4 votes
2 answers
145 views

Fetching data closure completion

I started learning MVVM and API data fetching, so I made this code: Function loadDirector in which directorName value is ...
Jule's user avatar
  • 41
3 votes
3 answers
738 views

Generate all subsets of a set

The goal of the function below is to generate all subsets of a given set, i.e. a collection of sets that contain all possible combinations of the elements in the set. Note that for my application I do ...
Alexandre Bintz's user avatar
2 votes
2 answers
207 views

Initialize Swift class or struct values inline

For a Metal application, I would like to create and initalize texture object globally so it will not have to be optional, and will already be ready to use once ...
user244312's user avatar
3 votes
1 answer
129 views

Structure and readability of the code in swift ios

For a job in company I had to do a code assignment. My assignment performs all the required tasks needed to be done. But after one month the company provided me a feedback and said that we have ...
Cluadia Hedda's user avatar
3 votes
2 answers
140 views

Determine final player in a counting game

I made a function in which 17 players are counting to number N. Function as a parameter takes a number N and returns which player is going to say N. If current number is divisible by 9 the counting ...
Sah Sah's user avatar
  • 31
2 votes
1 answer
141 views

Monte Carlo Tree Search Optimization and Loss Prevention

I'm working on an implementation of Monte Carlo Tree Search in Swift. It's not bad, but it could be better! I'm principally interested in making my algorithm: faster (more iterations/second) ...
emehex's user avatar
  • 121
2 votes
0 answers
212 views

Fixed-width non-FIFO DispatchQueue

I have implemented a custom concurrent queue on top of GCD which offers two additional pieces of functionality: Limit the maximum number of concurrently executing tasks. Give manual control over ...
Marcel Tesch's user avatar

1
2 3 4 5
14