Stack Exchange Network

Stack Exchange network consists of 174 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.

1
vote
1answer
13 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
36 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
39 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
45 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
10 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
29 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 ...
0
votes
0answers
42 views

Parse tokens into statements for compiling efficiently [closed]

You can see the code here on GitHub but I am going to ask about one part, and that is the makeExpression function. ...
0
votes
0answers
15 views

Custom map annotations and clusters

I registered a CustomMapAnnotationView and a ClusterView: the first one simply extends ...
0
votes
0answers
20 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
145 views

Dijkstra algorithm implementation in Swift

I've implemented Dijkstra's algorithm to find the minimum path between two nodes. ...
2
votes
0answers
138 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
69 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
42 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
99 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
78 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
90 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
47 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
36 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
124 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
82 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
71 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
67 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
100 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
100 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
155 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
140 views

Valid Sudoku in Swift

This is my solution to LeetCode – Valid Sudoku in Swift. ...
0
votes
1answer
52 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
17 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
87 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
110 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
38 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
66 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
31 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
124 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
49 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
127 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
78 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
115 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
92 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 ...
1
vote
0answers
27 views

Reducing force unwraps in CLI utility

This is a CLI utility for managing the allocation of investment. It's an exercise, don't take it too seriously. So the utility asks the user a series of questions about it's finances and suggests a ...
2
votes
1answer
99 views

Manage Game Level with enum

Basically What I have is basket ball App. In which I have Added some levels and difficulties. logic is simply use tupple in enum and I have some methods to update / get current level with new values ...
0
votes
2answers
105 views

Creating an Enum with a Custom Type in Swift 4.x

I was in a code review today and someone said, "Why don't you do an enum on that?" I had started to, but conforming to a bunch of protocols seemed like a gigantic ...
1
vote
2answers
701 views

Form for OTP entry with six single-character text fields

I am working on an app in which I have to pass 6 digits OTP through 6 textFields in which you to provide only one character and after that it automatically goes to ...
1
vote
0answers
42 views

Probability shooting game

I've been working on this probability game that has a gun with 5/6 bullets. When there's a dodge the game removes a bullet and then the game continues, the goal being to get to 0 bullets. I don't use ...
2
votes
2answers
128 views

Finding a word that represents an image

This is an app wherein you have to find the word that represents the image. It's the same concept as the course app but I did this one myself. How can I improve this code (put more commentary, put ...
0
votes
0answers
41 views

Two different blocks with reverse direction in single method in Swift

So I've been trying to refactor my existing code for loading data from server and synching it to the local DB. Initially there were multiple methods with duplicated pattern, then I refactored them ...
2
votes
1answer
223 views

Swift - Finding longest binary gap of a given integer

I recently had the chance to try Codility's algorithm training, and the very first one in the list is finding the longest binary gap of a given integer. I tried to implement this in Swift, and after ...
2
votes
2answers
216 views

Sequence-based enumeration of permutations with Heap's algorithm

Heap's algorithm is an algorithm to generate all permutations of a given array. It ... generates each permutation from the previous one by interchanging a single pair of elements; the other n−2 ...
3
votes
1answer
59 views

Dividing an arbitrary dollar amount into the fewest bills and coins

I am taking a class in mobile application development this fall. I have finished my first assignment of creating a class to divide an arbitrary dollar amount into the minimum number of bills and coins....
0
votes
0answers
18 views

FilterOnTrigger Operator

Any constructive critiques on this operator is appropriated. This could be used, for e.g., to allow a stream to flow only when a UISwitch is set to on. (The switch's value producer would be the ...