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
6 views

Is this code messy and sparse?

I would like to request iOS developer community to please review my POC https://github.com/pooja-iosTech13/GithubUserFinder which I have created as part of job screening test at T-mobile Bengaluru. I ...
1
vote
2answers
100 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
0answers
39 views

sharing and decoupling data

I basically want to know how you would review this code and design. Right now, there seems to be a tight coupling so I feel like I've violated some rules about ...
3
votes
0answers
25 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
111 views

Create UIView programmatically in Swift

I am generating View and setting constraints programmatically in UIViewController ...
0
votes
1answer
44 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
15 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
49 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
3answers
89 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
36 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
0answers
16 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
23 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
33 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
42 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
31 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
73 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
77 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
30 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
96 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
46 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
14k 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 ...
5
votes
2answers
159 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
574 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
381 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
118 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 ...
2
votes
2answers
133 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' ...
0
votes
1answer
92 views

refactor function so same code is written only once

I have this code ...
2
votes
2answers
110 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 ...
44
votes
0answers
1k views

Swiftly turning wheels – The May 2017 Community Challenge

This is my attempt at the May 2017 Community Challenge in Swift, with a chain consisting of rigid links. I took this as an opportunity to learn SpriteKit, Apple's framework for 2D games. At least ...
4
votes
1answer
93 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
299 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
62 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
30 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
76 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
75 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
91 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
43 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 ...
7
votes
1answer
657 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
298 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
577 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
1answer
135 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 ...
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 ...
2
votes
2answers
77 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
133 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
6k 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
81 views

Identify MOT Dates which could be in various formats

I want to significantly tidy this code as its cluttered and repetitive ...
3
votes
1answer
131 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