Questions tagged [swift]

Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development.

Filter by
Sorted by
Tagged with
3
votes
0answers
16 views

Swift iOS app for showing motivational quotes, with multiple screens

I'm one month into self-learning Swift, and I would like some advice to improve my coding skills. I have listed 2 situations that I think I need to improve. I'd like some feedback focusing on my use ...
2
votes
0answers
20 views

Basic network layer for a JSON API client

Just looking for some feedback/ways to improve this basic networking layer written in Swift. I'm still learning, please elaborate with as much detail as possible. ...
-1
votes
0answers
26 views

Sorting objects primarily by date, and secondarily by title [closed]

Using Swift, I am sorting through some objects first by date order, then secondly by title if the date is the same, as per the extract below: ...
1
vote
1answer
36 views

Playing a sound depending on the currently displayed flash card image

I've developed a fully working flash card app for kids. It has a UIImageView that cycles through 26 cards (abcs) via a gesture click and a music button that will ...
3
votes
1answer
58 views

Jumping on the clouds

I have started the Hackerrank interview preparation kit. The first problem I have solved with Swift is as follows: Emma is playing a new mobile game that starts with consecutively numbered clouds. ...
2
votes
0answers
19 views

Swift MVVM: Repositories - loading entities and dependency injection

I create a lexikon and a navigation for ZOO. I use MVVM architecture supported by ReactiveSwift. I have a few questions about my practises and whether I could write my repositories better and more ...
1
vote
0answers
18 views

Keychain unique user

I want to be able to store and retrieve a unique user throughout the app. Multiple accounts are not used. The code I have written is stated below. This is my first attempt using KeyChain. The test ...
2
votes
1answer
104 views

Find indices of white space characters in a string

This function returns the indices of all white spaces as an array of Integer. It works fine with a small string: ...
3
votes
1answer
62 views

Create Products TableView with PAGINATION and LIKE product feature in RxSwift MVVM

I have tried to develop a simple product listing app in RxSwift with MVVM design pattern. I have managed to achieve it but I need someone to review my code, such as: Have I followed the proper ...
0
votes
0answers
25 views

Making Oauth request asynchronously, with retry if token has expired

I'm struggling with asynchronous code. Does anyone have suggestions of a better way to do the following? What I'm doing: hitting an API (google's, actually), with a call that might get a 401 if the ...
1
vote
1answer
63 views

Sequence for Pre-order traversal of Binary Trees

I wanted to make a Sequence that can do a pre-order traversal of Binary Tree. Doing so provides automatically unlocks wonderfully useful methods, like ...
5
votes
2answers
146 views

Splitting an amount of money equally between a group of people

I'm building a clone banking app at the moment, and one of the things I'm trying to do is add Split Transaction (which can then be shared with a set of friends paying a given amount each). Initially, ...
4
votes
1answer
72 views

Force-unwrapped property as a contract

I have a class, which is meant to show a full screen modal controller with a set of actions (apart from actions it also has some static content, a lot of labels and images which are irrelevant, so I ...
3
votes
1answer
50 views

Core Data Wrapper

I built a wrapper in Swift to practice CoreData. My question is more general, I hope this is acceptable. I wanted to know whether my implementation of this wrapper is correct or poorly implemented ...
5
votes
1answer
42 views

Enum for handling network request errors in Swift

I'm working on a new API written in Swift 5 and I wanted to play with the new Result. I wanted to know what you guys think about this syntax: ...
3
votes
1answer
66 views

Implementation of a property and a corresponding animated setter

There a various examples in UIKit where a class has a property and a corresponding method to set the property along with an animated property. Examples include the ...
2
votes
1answer
53 views

Finding the most common section from the visible cells in a collection view

My goal is to determine, of all of the currently visible cells in a collection view, which section has the most visible cells. Start by getting the index paths for the visible cells: ...
3
votes
1answer
111 views

Swift function to find a specific set of combinations of 3 digits within a larger integer array

I asked this question on Stack Overflow and was directed here. I'm working on a function that will help me quickly find all the upper structure triads (3-note chord) that I can add to a 4-note 7th ...
1
vote
2answers
178 views

Multi-Threaded Cellular Automata Lab

I am trying to improve the performance of my cellular automata lab. I have two arrays of Doubles representing the current values and the next values. If I run the ...
4
votes
2answers
116 views

Translating Objective-C use of static and +(void)initialize to Swift

I am converting an old Objective-C class into Swift. My actual question is at the very end after all of the code. Here is a cut-down version of the Objective-C class: DateInfo.h: ...
3
votes
1answer
159 views

Splitting a long string based on its graphical presentation

I got a long string, let's call it Story. I fetch this story from a database so I don't know how long it is. I want to display this story in a view, but what if ...
1
vote
1answer
38 views

Calling API only once on changing segments

I am working on a screen which has segmented control and has 3 segments (year value 2019, 18, 17) and what I am doing is that on each segment click I have to reload data inside a tableview (getting ...
2
votes
4answers
454 views

Showing a welcome screen once per day

I have this method, which first basically shows a Welcome screen to user only once per day. The code I have so far is this ...
3
votes
1answer
109 views

Login page using RxSwift in MVVM

I am building a simple login page which will check for username before navigating to another screen and here is how I am doing the binding now. I would like to know if I am doing it right and if I am ...
2
votes
1answer
59 views

Table View Controller class in Swift

My TableView consists of four cells (for blacklisting categories) with a boolean property (indicated with a checkmark) and another cell with a UISwitch embedded in ...
3
votes
1answer
110 views

MVVM in Swift iOS

I've been implementing MVVM in Swift. I've looked at several implementations, many of which violate some aspects of MVVM and wanted to have a go with my own version that contains a Web request service....
3
votes
2answers
129 views

Efficient way of flat mapping a range of a multidimensional random access collection

I've recently answered a question about reading elements from an array of arrays. A way it could be interpreted is that the OP wanted to read a range that could span over multiple subarrays of the 2D ...
5
votes
1answer
148 views

Networking structure for Swift iOS app

I would like any constructive comments regarding the structure of this simple App that takes an API response and then displays on a table view. The URL is written in a ConstantsAPI file ...
2
votes
0answers
16 views

Simplifying a firestore querying function

I have this function where it queries through the database and returns a random user if the requirement is met if not then try it again. It works and all but I feel like the code could be better/...
2
votes
1answer
66 views

Swift Memory Cycle From Closure

I am working with closures and want to confirm that I do not have any memory leaks in my code. Below is my current code: ...
4
votes
1answer
63 views

Swift Prim's algorithm

Lots of Prim's algorithm implementations seem long, and rely on a priority queue implementation. If I use an adjacency matrix I can then calculate the next item to take using functional programming ...
1
vote
0answers
51 views

Swift lazy observe and mutate pattern for arrays

I am using the following pattern in my code. It works. But, it feels as though it is on the edge of what should work! Should I consider an alternative? I have an array in my class that maps an ...
0
votes
2answers
146 views

Counting sort in Swift

I have this sorting algorithm which takes an array of dictionary values: guard var imageUrlString = anyImage.value as? [String:AnyObject] else { return } I then ...
2
votes
2answers
116 views

Formatting a price in Swift using an extension vs. a class

I have a price as a Double, which I should format it as a String. Should I use an extension instead of classical class to ...
7
votes
3answers
201 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: ...
1
vote
1answer
93 views

Generating all subarrays from an array of Integer

I want to generate all the subarrays from an array of integer as below: ...
2
votes
1answer
67 views

Swift: arrayToTree() where array contains int and nil

I am learning tree on Leetcode. Need to prepare the testing data. It is easy to convert the array to an organized node, where its elements are integers. such as ...
3
votes
1answer
111 views

Leetcode 102: Binary tree level-order traversal in Swift

102. Binary Tree Level Order Traversal Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level). For example: Given binary ...
2
votes
1answer
72 views

Codable Failure Response Handler

Suppose You have two kind of response like one for success and one for failure Success response model will looks like ...
0
votes
0answers
82 views

Swift Knapsack problem using bottom-down (memoization) approach

I'm solving the "unbounded" variant of the knapsack problem, meaning the repetition of items is allowed. As in the Hackerrank version of the knapsack problem, I am returning the sum nearest to, not ...
3
votes
1answer
111 views

Custom map annotations and clusters

I registered a CustomMapAnnotationView and a ClusterView: the first one simply extends ...
0
votes
0answers
61 views

Using unique objects in CoreData

I am not very familiar with CoreData, some I am not sure if the way I am handling relationships between objects is the right way to do it. I have the following ...
5
votes
1answer
199 views

Dijkstra algorithm implementation in Swift

I've implemented Dijkstra's algorithm to find the minimum path between two nodes. ...
3
votes
1answer
169 views

Design pattern: image downloads

This is an image representation of my code below: This is what they do: CellWithImageX: Subclasses of UITableViewCell. They have an image and an loading indicator....
2
votes
1answer
132 views

Faster Sieve of Eratosthenes

This is an implementation of the Sieve of Eratosthenes : It takes advantages of the fact that all primes from 5 and above can be written as 6X-1 or ...
1
vote
1answer
54 views

Find index of array item starting at a given location

I've written a lot of C++ but now I'm learning Swift. I did an exercise, the standard Sieve of Erastosthenes. It works fine, but it seems a bit clunky and I wonder if I'm missing some language ...
1
vote
2answers
215 views

Playing Card in Swift

I'm trying to properly write a card class in swift. I've been taking classes in software engineering and I need help in understanding how to take a more object-oriented approach to my class. I have ...
1
vote
1answer
90 views

A quiz to practice some of the notion of the chapter four of app development with swift

I just want feedback about the code. Better implementation, more commentary etc. app Delegate.swift ...
2
votes
1answer
120 views

Quiz app with Practice and Exam modes

I am building a Quiz app in swift (my first app) to practice a few skills (using CoreData, working with plists, UIKit etc.) and later to work with a server which stores the Exercises. Here's my ...
0
votes
0answers
63 views

Generic Caching class For RxSwift

The latest version of the class can always be found at: https://gist.github.com/dtartaglia/bf24b3b59dd33fef4cfa568d0e47f91b Did I miss anything? Is there anything I can do to make the code more lean ...