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
2answers
95 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.: ...
0
votes
0answers
16 views

Swift code for playing a video with different action buttons

This is a ViewController to play a video with some different control buttons. I would like to have feedback on the code structure etc. I am not an expert in Swift, this is a way of learning. ...
1
vote
1answer
50 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 ...
1
vote
0answers
26 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 ...
1
vote
1answer
99 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 ...
1
vote
1answer
48 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 ...
1
vote
1answer
20 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 ...
0
votes
0answers
85 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 ...
1
vote
1answer
260 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 ...
4
votes
2answers
124 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 ...
3
votes
3answers
237 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 ...
2
votes
2answers
100 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 ...
3
votes
1answer
85 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 ...
3
votes
2answers
133 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 ...
2
votes
1answer
95 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) ...
0
votes
0answers
239 views

iOS: Combine and Clean Architecture

I’m learning a lot of from Combine thanks to an amazing book in raywenderlich. Currently i’m writing an app and following the clean MVVM architecture. Then I have the following layers: Domain(...
2
votes
0answers
163 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 ...
1
vote
0answers
30 views

Subclassed DiffableDataSource

This is a datasource for Achievements that can be toggled to be viewed within a grid or list layout. Thoughts/notes This code was previously duplicated in two different ViewControllers. Should the ...
2
votes
1answer
127 views

Swift code to extract most common page sequences from an Apache server log

So I received the following prompt for a code interview: "Please create an iOS app that downloads a text file from our server, parses the contents, and displays the results. The file is a ...
0
votes
1answer
67 views

Add protocols inside the same file as controller

I have a question about something maybe not so much important, but every time when I have to decide, I feel it can write in another way. Imagine I am developing and system about authentication and ...
0
votes
1answer
471 views

Is this a good way to download images from json Api?

In my SwiftUI app, I'm trying to get some data from a json Api and display this data along with an image. First I have a function that fetches the data from the Api, then I have another function that ...
-1
votes
1answer
157 views

Use of parentheses in Swift [closed]

I am learning Swift and just had a quick question about use of parentheses. The code below runs just fine w/o using parentheses, but it certainly looks a lot cleaner using them in this instance. So my ...
2
votes
0answers
629 views

SwiftUI custom ScrollView with snap interval

Due that fact that SwiftUI has poor ScrollView customization and doesn't support snap interval from the box I decided to implement my custom component to support ...
3
votes
1answer
79 views

macOS: resetting balance to center (0.5) using Swift

Due to some bug somewhere, my speaker balance kept moving off-center and it was getting annoying. So I cobbled together the code below (based on this question) which—to my surprise—does compile and ...
1
vote
3answers
605 views

Convert first letter of every word to uppercase

I am learning swift and I came across this problem. Converting each start letter to capitalized form if it's lowercase. ...
0
votes
2answers
128 views

How to load and get data from 2 files

I want to load 2 files and show this data in 2 strings. I trying to do it like this and it works fine. But I think it is not the best solution... How to do more elegant solution? ...
2
votes
0answers
123 views

A Daily goals list 'Dopamine Box'

Inspired by Mike Boyd's 'Dopamine Box' video: link, I decided it would be a good project to pursue by myself in swift. The end goal is to make it look like the box in the video, with switches and a ...
0
votes
1answer
142 views

Sqlite select and delete operation using C API in Swift

I've following sqlite code using C api within Swift having a read and a delete operation for review. For those not familiar with Swift, defer will execute after the ...
4
votes
2answers
450 views

Better way to provide data to UIKit component from Combine pipeline

Today I'm researching how to provide data to UIKit component when using Combine pipeline. I could see tons of tutorials about how to use SwiftUI + Combine from internet, but not found anyone helpful ...
1
vote
1answer
257 views

Create buttons with MVVM architecture

im trying to migrate my very large swift view controller to mvvm but it still feels very large, can you guys give me any advice What this controller does is simple it shows a UIView on which i can ...
4
votes
1answer
193 views

JSON parsing service

I created the following service for the purpose of sending in a file for parsing. I'm using the generics so that when I call parse() I can pass a custom type ...
2
votes
1answer
137 views

Display a Text() with a foreground color based on a condition

I decided to write a simple tab bar for macOS using Swift. tabs.swift ...
3
votes
1answer
112 views

Swift iOS rewrite a function that use Firebase database without updating a global variable

I'm learning swift programming and i built a music trivia app for iOS that use firebase real time database. I have a function that before the game start get the number of record for each category of ...
4
votes
1answer
96 views

Decoding indeterminate types using JSON Decoder

I'm working with a REST service that responds with indeterminate types. In particular, it can respond with a String, a correct payload (...
1
vote
1answer
42 views

"Pick up" images when tapped on and keep track of it

Trying to get my first job as a developer I made an app I was extremely proud of: https://github.com/AnatolyRudenko/Crystals.Dragons The game starts in a random room of a random maze. Some prebuilt ...
2
votes
1answer
75 views

Which is better-way to casting model

I need to convert my model to fit data in tableview cell finding better approach ...
2
votes
1answer
141 views

UIView position updates based on device motion via RxSwift

I've created a simple function to work as a level, where the dot on screen is centered when the device is completely flat. It changes position based on device orientation. I use RxSwift to update the ...
5
votes
1answer
297 views

Sorting JSON items from a site

So I recently applied to this job for iOS Developer and was invited to complete the following code challenge: As a next step, please complete this coding exercise in order to proceed with our ...
2
votes
1answer
112 views

Projecteuler.net Problem 2 using collection pipeline Pattern

I solve projecteuler.net Problem 2 deferent way Generate number from 1 to range ex 100 and get the even number Get Fibonacci numbers from list Reduce array I have one problem with a large set of ...
1
vote
0answers
261 views

Simple bruteforce algorithm in Swift

So, I am learning Swift and as a little exercise I tried to implement a BruteForce algorithm. That algorithm is pretty simple however it is a bit slow too... Well, I am new to Swift, so maybe some ...
1
vote
1answer
158 views

Improving sqlite3 code in swift using c api

Trying to come up with a pattern where the code to open db, writing queries is elegant and clean while handling all possible error conditions. Following code ...
1
vote
1answer
174 views

Swift NSCache Singleton

I want to wrap NSCache in a Singleton in order to use dependency injection in my code. This has resulted, rather unfortunately, in passing the type through a function parameter, and I even need two ...
3
votes
2answers
72 views

A Start button handler

I was told my code contains a lot of force unwrapping. I thought it's okay to do that if I am sure that the value operated won't be nil: ...
5
votes
1answer
217 views

Decoding a JSON dictionary into different Swift classes using Decodable and JSONDecoder

Generally, the approach I've taken is to try calling container.decode from a decodable enum with its associated value returning ...
1
vote
0answers
29 views

Plugin architecture to extend/customize behavior of white label swift based application

I have a white label swift based application in which I need to change behavior depending on the customers. I would like to add that behavior in a dedicated framework in classes/struct that would be ...
3
votes
0answers
369 views

Navigation strategies for a SwiftUI-based app using MVVM pattern

I'm finding it difficult to decide on the best architectural pattern for a SwiftUI app but, for the moment, I'm sticking with MVVM as I found this a good fit conceptually. I'm trying to avoid the ...
1
vote
1answer
83 views

Generic memoize function in Swift

I need to perform some expensive calculation, such as determining a Fibonacci number: ...
3
votes
1answer
64 views

Granular vs a aggregated tests when dealing with arrays

I write code in a Test-Driven way and I often build my functions starting with tests for the easy edge cases. For example, given a flat array of Items that have a <...
5
votes
1answer
290 views

Binding ViewModel to ViewController using RxSwift

I have a ViewController and ViewModel. Here I am using the .subscribe() method too many ...
3
votes
1answer
87 views

Break music player into usable components in SwiftUI

I created a music player using swiftUI.I need to ask a question when I break up my player into usable components. How should I take this approach with the music player? because the music player is one ...

1
2 3 4 5
14