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
25 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 ...
5
votes
1answer
112 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
78 views

Swift Struct-based Factory Pattern

Edit: I added another configuration vector to CardView, a size attribute, which may be .small or ...
2
votes
3answers
126 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. ...
4
votes
1answer
356 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
112 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 ...
2
votes
1answer
293 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? ...
1
vote
1answer
50 views

Service Locator with Lazy Loading in Swift

I am experimenting with the ServiceLocator pattern. I'd like to support lazy loading of items. ...
8
votes
3answers
608 views

Leetcode 38: The “count-and-say” sequence

38. Count and Say The count-and-say sequence is the sequence of integers with the first five terms as following: ...
4
votes
1answer
98 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 ...
1
vote
2answers
140 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 ...
3
votes
0answers
103 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
3answers
1k views

Create UIView programmatically in Swift

I am generating View and setting constraints programmatically in UIViewController ...
1
vote
1answer
65 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
61 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
54 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. ...
2
votes
0answers
34 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
68 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
153 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 ...
2
votes
2answers
1k views

Project Euler #13 in Swift - Large sum

I just finished Project Euler #13 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. Work out the first ten ...
1
vote
1answer
35 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 . ...
0
votes
1answer
88 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 ...
1
vote
1answer
81 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 ...
4
votes
0answers
36 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 ...
2
votes
1answer
151 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 ...
3
votes
1answer
54 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 ...
6
votes
2answers
3k views

Canonical Implementation for a Concurrent Subclass of NSOperation in Swift 2

I would like to develop a kind of template or canonical implementation for a concurrent subclass of NSOperation in Swift. See here for my previous request which is implemented in Objective-C. In that ...
7
votes
1answer
15k views

Hex String to Bytes (NSData)

I'm trying to convert this Objective-C code (originally found in this Stack Overflow question) which turns an NSString into ...
6
votes
2answers
333 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° ...
3
votes
2answers
731 views

Tableview Subclass implementing delegate datasource

I have two view controllers which have same tableview. One is for Post and one is for Profile, which also contains a post by a user. I have decided to reuse the code, so I have created the class ...
5
votes
1answer
542 views

Draw a spark line with SwiftUI

I am using a set of data points (currently randomly generated), and drawing a line graph inside a box: ...
-2
votes
1answer
400 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
45 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
102 views

refactor function so same code is written only once

I have this code ...
2
votes
2answers
121 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 ...
4
votes
1answer
132 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
925 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
68 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. ...
1
vote
0answers
32 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
83 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: ...
1
vote
1answer
114 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 ...
0
votes
0answers
292 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 ...
7
votes
1answer
666 views

Generating Phone Words in Swift

I've been playing around with some basic algorithms in Swift. Here I am trying to generate phone words, words which can be mapped from phone numbers using the characters under each digit. I was trying ...
4
votes
1answer
305 views

Notify user of credential failure and make another attempt

The below code works because of the do operator on line 24. Is there a more functional way to get the test to pass, or would you consider this an appropriate use of ...
3
votes
2answers
1k views

Working with Arrays in Swift

It's an exercise from a Swift-course I'm currently taking. You are given an array of integers. Make an additional array named computedNumbers. computedNumbers should multiply each element in the ...
3
votes
2answers
118 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 ...
2
votes
2answers
97 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 ...
1
vote
1answer
230 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 ...
5
votes
1answer
7k views

Countdown timer in every table cell

I am making countdown app with multiple records, so I am using UITableView to show that records and countdown dates. What I do is just take one timer and reload cells on every second. Is this a best ...
2
votes
2answers
85 views

Identify MOT Dates which could be in various formats

I want to significantly tidy this code as its cluttered and repetitive ...

1
2
3 4 5
13