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

Optimize chess piece string location to an index

This code works for converting a chess piece location to an index. A chessboard piece describes its location with file a-h (x-axis) and rank 1-8 (y-axis) so this can be represented with indices from ...
-3
votes
0answers
24 views

SFSpeechRecognizer doesn't fire recognition closure [closed]

I have to use AudioToolbox instead AVAudioSession for providing stream to SFSpeechRecognizer. So I made an audio recording with AudioQueue for export to CMSampleBuffer to read it with recognizer. And ...
1
vote
1answer
58 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
58 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 ...
3
votes
0answers
20 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
43 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
108 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
95 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
38 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
84 views

refactor function so same code is written only once

I have this code ...
4
votes
1answer
89 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
144 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
59 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
106 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
29 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. ...
4
votes
1answer
67 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
65 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
41 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
0answers
20 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
80 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
72 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
108 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
116 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
114 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
74 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
81 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
81 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
103 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 ...
2
votes
2answers
315 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 ...
2
votes
1answer
56 views

UITableView, auto locate back at indexPath when user drags it

I have a tableView, which auto locates back at indexPath after user has dragged it. In other words, bouncing the tableView back into its bounds, after user dragged it out. Here is the code: ...
2
votes
1answer
80 views

Testable network calls Swift

I want to make testable network calls using Swift. For example, I want to download the latest from AWS if and only if it's version is newer than the downloaded file. In order to do this I've created ...
0
votes
0answers
63 views

Test A Swizzling Swift method

I've a method that swizzles out the the localization bundle for another put in the project build. It works great: ...
1
vote
0answers
38 views

Message handling: Should a test/spec do it?

I am currently implementing an app that uses an architecture based on features & usecases and message sending. Features are created with message handler passed in. To test the feature, a handler ...
3
votes
1answer
241 views

Swift protocol with lazy property requirement

First question here on CodeReview. I was directed here from a question I asked on SO: Swift protocol with lazy property - Cannot use mutating getter on immutable value: '$0' is immutable. Goal: ...
1
vote
0answers
26 views

Test a method that Swizzles in Swift [closed]

How can I test a class that Swizzles? In particular, I want to test the following: ...
4
votes
2answers
207 views

Swift main thread style

I run into issues where I forget to run UI changes on the main thread. I've just fixed an issue for loading and unloading an activity indicator and fixed it with the following code: ...
1
vote
0answers
90 views

Clean way of passing parameters in swift

I am creating a user request model to pass-params for web service call toRegisterParams() is used call register web service request toLoginParams() is used call register web service request so my ...
4
votes
2answers
191 views

Finding a perfect square smaller than an input number (Swift)

This code runs slowly, even with numbers smaller than 1,000,000. Can someone help me optimize this thing? ...
4
votes
2answers
67 views

Reducing a list of points into a list of pairs of points

I have some data… let points = [(718, 620), (4596, 1280), (410, 333), (4597, 993), (410, 337), (4597, 996), (428, 337), (4597, 1000), (431, 335), (4599, 1044)] …...
1
vote
1answer
172 views

Swift: extract string with regex and range

In Swift, I have a string like this http://mnc-hdqp.oss-cn-shanghai.aliyuncs.com/user%2Fheat%2Fdefault.jpg?Signature=2BI%2BauSvy&Expires=1568682491&OSSAccessKeyId=LTAIQ8Lif1HHVkXd Need to ...
2
votes
0answers
58 views

Convenient way to make an UIImageView ExpressibleByStringLiteral

I want to reduce boiler-plate code and write like this when developing in iOS: let imgView: UIImageView = "share_fareware_text_bg" Here is implementation code: <...
5
votes
1answer
342 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: ...
0
votes
0answers
53 views

Sending callback using RxSwift from UITableViewCell to UIViewController

I have a UITableViewCell in which I have customContentView on tap of that view I want to send a call back to the ...
4
votes
1answer
86 views

Parse data into an array of structs

I'd had a hard time getting this to work. I’d like to parse a file containing data and copy this data into a struct. The data file (test.dat) looks like this: <...
1
vote
0answers
45 views

Combining the text from selected TextFields into 1 TextView - Conditionally [closed]

ViewController2 (source) Has several TextFields, each with their own switches. ViewController1 (destination) Has one TextView waiting for data to be sent to it from ViewController2 (source) But i ...
1
vote
0answers
104 views

iOS Calendar Navigation and Layout

In an effort to explore how the default calendar app works and to experiment with container view controllers, I created the following mock app. See this post for more info about my motivation for this ...
3
votes
1answer
226 views

LinkedList Swift Implementation

Linked List Implementation in Swift Swift 5.0, Xcode 10.3 I have written an implementation for a doubly linked list in Swift. As well, I decided to make the node class private and thus hidden to the ...
1
vote
0answers
58 views

Preventing tampering with save game data (iOS)

I am creating an iOS game with In-App purchases for "Coins" and I wish to prevent (or make it very difficult) for the user to simply edit the save-game file and increase the number of "Coins" without ...
3
votes
1answer
75 views

UITableView allowing some kinds of requests to be deleted with swipe gestures

I have a tableview which shows a list of objects called Requests. It has 3 segments. Namely Accepted, Received and Sent. And the objects for each segment are in 3 arrays. I want to enable deleting ...
2
votes
1answer
65 views

FizzBuzz with more parameters in Swift

Here's my approach to an extensible version of the FizzBuzz challenge in Swift (so one can add more numbers to be checked against other than just 3 and ...

1
2 3 4 5
12