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
0answers
2 views

How this swift function can be more simplified?

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
78 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
37 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
114 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
18 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
112 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
62 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
138 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
2answers
97 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
214 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 ...
1
vote
1answer
64 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 ...
0
votes
3answers
183 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
92 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
92 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
78 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
119 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
100 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
147 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
74 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
76 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
95 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
39 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
72 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
105 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
265 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
71 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
189 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
90 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
102 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
66 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: ...
4
votes
1answer
115 views

How to properly decode 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
26 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
233 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
61 views

Generic memoize function in Swift

I need to perform some expensive calculation, such as determining a Fibonacci number: ...
3
votes
1answer
56 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
139 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
74 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 ...
2
votes
0answers
96 views

Swift Struct-based Factory Pattern

Edit: I added another configuration vector to CardView, a size attribute, which may be .small or ...
3
votes
1answer
223 views

SwiftUI Dot indicator

I want to understand if I got this concept correctly. I should start work from ViewState; a reference type object holding the state of a view. Here it is called <...
2
votes
1answer
131 views

Trie implementation for strings in Swift

A trie for handling strings for an autocomplete dictionary. This passes my fairly casual tests, though it's always possible that there are broken edge cases, but I'm mainly concerned about design and ...
4
votes
1answer
495 views

Rock Paper Scissors in Swift

I'm going through the eBook Intro to App Development with Swift by Apple and I am making the Rock, Paper, Scissors app in lesson 20. This is the assignment that I got: [...] Name the enum ...
2
votes
1answer
384 views

MVVM-C Swift with Dependency injection

I want to create a MVVM-C project, but also adequately test it. Naturally I want to create such a project that can access a Network Service. Any comments or thoughts on this approach? ...
4
votes
1answer
99 views

POC for GithubUserFinder

I would like to request iOS developer community to please review my POC i.e. [GithubUserFinder][1] which I have created as part of job screening test at T-mobile Bengaluru. I have around 2 years of ...
3
votes
0answers
128 views

Combine asynchronous return values in SwiftUI

I have 2 asynchronous return values from 2 different classes, one from HealthKit, the other from MotionManager. I combine the outcome of these classes through a combinedViewModel. The code works, but ...
1
vote
2answers
147 views

Trying (and failing) to implement the best conventions on OOP Swift

I'm making a MacOS app that will do some analysis on the user's calendar data. For now it only supports Apple's native calendar (EventKit), but I will later add ...
1
vote
1answer
66 views

Simple State Machine and Transition Table

The goal is to have well defined state transitions, and the ability to provide the next event to execute. I'd like to know if this is a proper implementation of State Machine, considering how states ...
1
vote
0answers
72 views

SwiftUI Passing closure between sibling views

This is my current View hierarchy: ParentView:View { ChildView1: UIViewRepresentable ChildView2: View } In ChildView2 I have a button who's action I ...
2
votes
2answers
107 views

Convert C to Swift

I trying to convert this C code for calculating distance from RSSI to Swift code. I try to do it by myself, but considering I'm beginner, I need help in how to do it. Here is C code: ...
1
vote
1answer
55 views

Singleton that holds the app's data

I currently have a singleton that holds the translation objects in my app. View controllers can subscribe to its delegate so they can update their views if new translation objects have been added. ...
1
vote
1answer
66 views

Service Locator with Lazy Loading in Swift

I am experimenting with the ServiceLocator pattern. I'd like to support lazy loading of items. ...

1
2 3 4 5
13