Skip to main content

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
0 votes
0 answers
28 views

Show a list of downloads

I've been working on a Swift project that involves a seedbox app for my NAS, and I would appreciate some feedback on the code structure and especially on the placement of my observer. I've implemented ...
Bam Bou's user avatar
0 votes
0 answers
44 views

Counting many to one relationship in Core Data

I tried to create simple application, yet I encountered problem with relationship using Core Data in SwiftUI. I have 2 simple models, ParentEntity: ...
ostojan's user avatar
  • 151
4 votes
1 answer
672 views

Caesar Cipher in Swift (iOS-app)

I have implemented the Caesar Cipher in Swift and incorporated it into an iOS-app. I guess it's formally correct. Please see the attached images, which show how the usage of the app is meant. Here's ...
michael.zech's user avatar
  • 4,294
3 votes
3 answers
180 views

Bubble Sort as extension to Swift-Arrays

Task description: Implement an extension for Array, which sorts the elements using the Bubble Sort-algorithm. My implementation: ...
michael.zech's user avatar
  • 4,294
2 votes
1 answer
168 views

Swift-function for finding missing Integers in an array of sequential Integers

Task description: Implement a function, which receives an array of unsorted numbers from 1 to 100. In the array zero or more numbers might be missing. The function shall return an array containing the ...
michael.zech's user avatar
  • 4,294
2 votes
1 answer
311 views

Swift-function: Copy directory recursively

Task description: Implement a function, which accepts two paths: The path to a source-directory & the path to a target-directory. The function shall return true if the directory has become copied ...
michael.zech's user avatar
  • 4,294
1 vote
1 answer
135 views

Implement the Swift pow(base, exp)-function yourself

Task: Implement a function, which accepts two integers and results the first number raised to the power of the second number. Both numbers have to be positive. Examples: The arguments 4 and 3 shall ...
michael.zech's user avatar
  • 4,294
1 vote
1 answer
124 views

Function, which replaces consecutive white-space with a single white-space

Task-description: Implement a function, which returns a string with all consecutive whites-spaces replaced as a single-space. Example: "a[space][space][space]b[space][space][space]c" shall ...
michael.zech's user avatar
  • 4,294
2 votes
0 answers
43 views

Swift: Fetch XML and check it's well formed

I want to download an XML and check to see if it can be parsed at all, no schema validation. I was thinking to write two free functions, to separate concerns and wrap them in a third, public API: <...
Dan's user avatar
  • 143
4 votes
1 answer
123 views

Is Palindrom-function in Swift

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

Swift-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
  • 4,294
2 votes
2 answers
243 views

Swift-function, which counts all occurrences 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
  • 4,294
2 votes
2 answers
97 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
  • 21
2 votes
0 answers
65 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
3 votes
1 answer
148 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
  • 179
4 votes
1 answer
142 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
3 votes
1 answer
98 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
153 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
537 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
3 votes
1 answer
128 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
544 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
159 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
  • 23.2k
5 votes
3 answers
234 views

Sum of natural numbers below threshold

I have this code: ...
Shum's user avatar
  • 53
2 votes
0 answers
67 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
2 votes
1 answer
189 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
241 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
81 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
199 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
  • 143
1 vote
0 answers
86 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
880 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
147 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
334 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
297 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
153 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
327 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
56 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
184 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
656 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
199 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
3 votes
2 answers
1k 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
  • 619
2 votes
1 answer
234 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
235 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 ...
Crocobag's user avatar
  • 113
3 votes
2 answers
398 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
187 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
108 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
6 votes
1 answer
4k 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
  • 143
2 votes
1 answer
3k 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
  • 123
4 votes
2 answers
152 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
986 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
290 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

1
2 3 4 5
14