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
1
vote
0answers
17 views

Generic memoize function in Swift

I need to perform some expensive calculation, such as determining a Fibonacci number: ...
1
vote
0answers
25 views

Protocol with generic array-like property [closed]

I'm creating a protocol to abstract different models (hand-crafted, decodable, and thrift-generated) like so: ...
2
votes
1answer
39 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
68 views

Binding ViewModel to ViewController using RxSwift

I have a ViewController and ViewModel. Here I am using the .subscribe() method too many ...
2
votes
0answers
19 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
32 views

Swift Struct-based Factory Pattern

Edit: I added another configuration vector to CardView, a size attribute, which may be .small or ...
1
vote
0answers
39 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
83 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
85 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 ...
1
vote
0answers
47 views

StateMachine Driven Workflow Design Feedback

Hi Im looking for feedback on design of my workflow - using state machine and swift combine. In my opinion, some aspects of the design violate single responsibility principle, cohesion, and overall ...
2
votes
1answer
124 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
95 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
59 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
123 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
56 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
27 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 ...
1
vote
1answer
63 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
49 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
30 views

Service Locator with Lazy Loading in Swift

I am experimenting with the ServiceLocator pattern. I'd like to support lazy loading of items. ...
2
votes
0answers
28 views

Idiomatic way to mutate array while using Swift dispatch groups

When keeping track of various pieces of information in a variable when using a dispatch group, I've fallen into a pattern of protecting the variable using a serial queue, and then ultimately notifying ...
3
votes
1answer
37 views

Unwrapping optionals for max of a 2D array in swift

I'm working in swift and I've got a custom class Array2D to handle fixed-width, two-dimensional arrays of integers. What I'm trying to do is write a simple, ideally-...
1
vote
0answers
49 views

iOS Core animation cancel and restart [closed]

There is a simple movement CAKeyframeAnimation, what needs is that I can cancel and restart the animation freely. The key point of the following code, is that I ...
1
vote
3answers
314 views

Create UIView programmatically in Swift

I am generating View and setting constraints programmatically in UIViewController ...
2
votes
3answers
105 views

I want to take away WebService call from UIViewController

I am using Moya to make network calls in Swift. In my ViewController I am calling the WebService and creating a model from response. ...
1
vote
1answer
80 views

Initializing more than one instance object at a time in init method

I have a RadioStation class file and a view controller where I create two station objects based on this class, one for FM and one for AM. I created both of these ...
0
votes
1answer
75 views

Where best to declare a counter variable to track number of guesses?

An exercise asks that we extend the below random number generator app to print to the console how many times the user guessed before guessing the correct random number. I first declared what I call ...
4
votes
0answers
33 views

Using UnsafeMutableRawPointers with Metal buffers in Swift

I've some Metal buffers which I populate with geometry data. Most data consists of Floats, but the buffer also contains custom structs for the tessellation stage. I ...
3
votes
1answer
47 views

Handle HTTP and BLE requests

Im implementing and designing a workflow that performs both HTTP and BLE requests. Im having trouble figuring out the best approach to design a service to handle both types of requests, and manage ...
5
votes
2answers
190 views

100DaysofSwiftUI - Project 1 - Challenge 1: Convert temperature units: Celsius, Fahrenheit and Kelvin

This is my code to solve the challenge in 100 Days of SwiftUI by Paul Hudson. This is the first challenge in the series and I chose to convert the temperature units from C° -> F°, F° -> C°, C° -> K° ...
-2
votes
1answer
158 views

Comparing two structs in Swift [closed]

Consider a struct with a name two Int values : struct StructWithNameAndTwoInts { let name: String let from: Int let to: Int } Now I want to compare ...
1
vote
0answers
42 views

Swift model for the Nevada Democratic Caucuses Feb 22 2020

Long one here, but election transparency is worth a rough code review. The Iowa Caucuses have numerous errors in delegate awards because they did their computations manually (their closed-source app ...
0
votes
1answer
96 views

refactor function so same code is written only once

I have this code ...
4
votes
1answer
96 views

Find minimum count of items where sum of them is X from an array

I recently faced an interview question where you have to find minimum needed items from an array that can added together to generate X value. For example giving: <...
2
votes
1answer
399 views

Dynamic Array Problem (Hacker rank)

I am trying to solve the Dynamic Array problem on HackerRank: Create a list, seqList, of N empty sequences, where each sequence is indexed from 0 to N-1. The elements within each of the N ...
1
vote
0answers
65 views

Finding the bundle of the most similar strings in an array

I used the minimum edit distance algorithm to find the bundle of the most similar strings in an array. So, I have to travel double for loop to compare all elements. ...
2
votes
2answers
112 views

Searching within a data model using an array matching multiple terms

I have a standard tableview app that displays information from a data model array that uses a custom class. There is a UISearchController to filter the data. A ...
1
vote
0answers
31 views

Manage Recent List Of user and staff type objects

So I have a view which shows recent 5 staff users and 5 customers for a restaurant app. I am storing this in user default. I am also managing the currently selected object. Here is my class. ...
5
votes
1answer
77 views

Function to generate an Int from a series of bits

I wrote the following function in order to handle some data from a QR code: ...
0
votes
0answers
126 views

Swift for flattening JSON nested objects

I am receiving JSON from a service API (Airtable) that returns an object with a single key records which is an array of objects. These objects have most of their ...
1
vote
0answers
45 views

iOS: prettify random color for debugging

iOS: prettify random color for debugging I used to use random color to debug, from colors I like ...
1
vote
1answer
32 views

iOS: configuring UI appearance and layout, use protocol to extract common code

There are many side controllers in my project, like the following images. They share the same head view appearance and layout. Use protocol to extract common code . ...
2
votes
1answer
110 views

iOS Body-Mass-Index (BMI) app

This is "homework" from a Swift course, which I'm currently taking. A mockup and the image-assets are provided by the instructor. We are supposed to create the layout and to write some appropriate ...
1
vote
1answer
78 views

Convert image to grayscale

To convert JPEG file, C function, bgraToGrayscale is called from Swift. Is there a better way to 1.allocate memory and 2.access pointers than the ways they have been done in code below? And ...
3
votes
1answer
175 views

Minimum window substring – LeetCode

Below is my code for the “Minimum Window Substring” LeetCode problem in Swift: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(...
3
votes
2answers
117 views

Pick a two different random elements from a given closed range

I wrote a function which picks a two different random elements from a closed range of ints and returns them as a tuple. I would like to take a your feedback, if the solution is a "Clever", "Best ...
1
vote
1answer
144 views

Unit Test class from iOS

I am learning to write test cases in iOS using Swift. I was stuck at testing static functions from my Utilities class, so I ...
2
votes
2answers
80 views

Handling view state for cardview

I have two buttons 1) Chat button 2) Annotation Button On tap each view comes from bottom and when tap outside view hidden back (Please refer the screen shot) On tap On annotation On tap on ...
2
votes
2answers
83 views

Identify MOT Dates which could be in various formats

I want to significantly tidy this code as its cluttered and repetitive ...
2
votes
2answers
161 views

Using enum to create, subscript and loop an array of structs in Swift 5.0

I'm trying to "build" a few "spaceships" in my code. I'm feeling it's a good idea to enumerate all the spaceships and use that as a subscript to build and use an array that holds the spaceships' ...
3
votes
1answer
147 views

ValueAnimator for IOS - Did I butcher it up?

I am trying to make an IOS tool similar to Android's ValueAnimator... more or less This is useful for situations where you simply want a value to "animate" over time, but rather than necessarily ...

1
2 3 4 5
13