Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [swift]

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

2
votes
2answers
288 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
25 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 ...
1
vote
0answers
23 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 ...
2
votes
1answer
79 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
111 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
111 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
13 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
54 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
56 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
39 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
127 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 ...
1
vote
2answers
90 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 ...
6
votes
2answers
141 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
72 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
61 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
84 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 ...
0
votes
0answers
24 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
61 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 ...
2
votes
1answer
57 views

Custom map annotations and clusters

I registered a CustomMapAnnotationView and a ClusterView: the first one simply extends ...
0
votes
0answers
31 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 ...
4
votes
1answer
174 views

Dijkstra algorithm implementation in Swift

I've implemented Dijkstra's algorithm to find the minimum path between two nodes. ...
2
votes
0answers
148 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
111 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
45 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
132 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 ...
0
votes
1answer
87 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
105 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
57 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 ...
1
vote
0answers
80 views

Side menu handling ios

I am playing with 3 Main Classes Please have a look I have integrated https://github.com/jonkykong/SideMenu I have one tableview which act as leftViewController This class is show the list of ...
2
votes
2answers
188 views

Swift permutations of the digits of an Integer

I want to return all of the permutations of an integer in Swift. ...
1
vote
1answer
115 views

Implementing `components(separatedBy:)` method in Swift

On looking at the components(separatedBy separator: String) -> [String] method from the Swift Standard Library, I tried to come up with an implementation just ...
3
votes
2answers
91 views

Creating a Swift game of Uno

I've starting writing the card game Uno the past couple of days and was wondering if you can review my code please. The initialization is done I think, a couple of game functions already exist, please ...
2
votes
1answer
125 views

Merge two UIImages into one

I have merge two images into one. I already implemented it with some help from the internet but it takes around 2,5s. I'm testing on the simulator so let's take it as a reference. I currently use <...
2
votes
1answer
117 views

Huffman Coding in Swift

I’m learning Swift and decided the Huffman Coding algorithm would be a good exercise while learning this new language. Below is a working version that encodes a ...
1
vote
1answer
107 views

Hashing interview puzzle

I've stumbled upon this pretty old article about a hashing interview question, and here it is converted to Swift in a more generic way: ...
1
vote
2answers
176 views

Minimum Area Rectangle in Swift

This is my solution to LeetCode – Minimum Area Rectangle in Swift 939. Minimum Area Rectangle Given a set of points in the xy-plane, determine the minimum area of a rectangle formed from these ...
2
votes
2answers
154 views

Valid Sudoku in Swift

This is my solution to LeetCode – Valid Sudoku in Swift. ...
0
votes
1answer
63 views

Initiating Child ViewController from UIStoryBoard in iOS

I'm trying to use inheritance in UIViewController where base class has XIB in storyboard. I'm troubling with initiating different children classes with that XIB. I ...
1
vote
0answers
25 views

Side Scrolling App Too Slow (using UIScrollView)

I'm building an app where the user can press play and then the app will scroll through some musical notes (like sheet music). I use a timer and counter to move the view along. The code works ok, ...
1
vote
0answers
118 views

Swift NMEA parser

I'm quite new to Swift, and although I've been programming as a hobby for many years, I'm still not very confident about my code. I'm currently rewriting an old library of mine, an NMEA parser. NMEA ...
1
vote
2answers
194 views

A scalable way to remove duplicates from Arrays without extensions in Swift 4

This method is an attempt at removing duplicates from arrays with scalability in mind in Swift 4 without the use of extensions. I am asking for any suggestions, criticisms, and/or observations. ...
1
vote
0answers
45 views

Design a system for renting digital movies/books

During an interview I was asked to do an OO design for a digital renting system for books/movies. This is the design that I came up with. My assumptions: When the customer has downloaded a list of ...
2
votes
1answer
71 views

Finding valid path on 2D Grid

I got a 2D grid (n x n matrix). The user selects his player in this 2D grid and after that selects another node in this grid to mark his destination position. The player is allowed to move ...
0
votes
1answer
33 views

Swift append an array when it's been declared as Any

I'm learning Swift and I have a following problem: I create a dictionary containing some data, one of which is stored as an array. I want make an operation on this array to add some info. Currently I ...
0
votes
2answers
134 views

Design a system for creating a coffeeshop menu

During an interview I was asked to design the menu for a coffee shop employee so that the employee would go and add different items to the menu. This is the design that I came up with. I just want ...
2
votes
1answer
54 views

How can this swift, firebase image fetching, function be made more concise?

I am trying to fetch a group of images within a place in Firebase database ref. I then loop through each image adding it to an array which is then supposed to be added to a tableview cell. I was ...
1
vote
1answer
142 views

Stack using Linked List in Swift

I made this implementation of a stack in Swift that stores its elements as a linked list. It seems to work perfectly well, but I’m wondering how I can improve it to follow the best practices of the ...
1
vote
0answers
109 views

Swift Throttler and Debouncer

I have a Throttler and Debouncer functions that I took from an unmaintained library. I added my own tests, but not sure if the ...
1
vote
1answer
165 views

Caesar encryption and decryption

For a small project, I had to implement Caesar encryption in Swift(4). I'm mainly looking for performance optimizations. This whole code should be copy and pasteable in a playground and is ...
1
vote
2answers
94 views

Converting a String to USD

I'm working on a clientside iOS app for my school that involves students purchasing things, and I wrote a String extension for formatting a ...