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
2answers
117 views

Implement The Singleton Pattern for Persistency managers Swift [closed]

I am creating an iOS app and I want to implement Singleton Pattern. I have created "Singleton" LibraryAPI to act as an entry point UserManager object to get data from web API. after that I used a ...
3
votes
1answer
221 views

Ring Timer Animation with Chasing Tail using CoreAnimation

After a fair amount of trial and error, I have gotten the animation acting in the manner that I want it, as seen here. However, I always feel like I'm writing way too much and too sloppily when trying ...
3
votes
1answer
191 views

Multilingual app without localizing

I'm making an iOS app which supports multiple languages but not in the built-in localized way. In iOS, for localization to work, the user has to change the device's language. But in the app I'm ...
3
votes
1answer
75 views

iOS app that signs people up for a street-ball league in their neighborhood

I know there is some repeated code in here, which is why I need a code review. The point of this app is simple, the user opens it, taps "begin", they select their league - men's, women's or co-ed, and ...
3
votes
1answer
2k views

Iterating 2D array in Swift

I have a situation where I needed to convert NSNumber 2D array to Float 2D array, so I did it like this: ...
3
votes
2answers
3k views

Body mass index calculator in Swift

Today I created my second app - a simple body mass index calculator. The BMI is calculated by the following formula: $$\dfrac{\text{weight}}{\text{(height)}^2}$$ The general meaning of the resulting ...
3
votes
1answer
16k views

Allow UITextView to resize as the user is typing

I want to be sure that in terms of auto-layout or just following the proper methods of doing the following is acceptable. I am not sure if there will be an constraint issues or efficiency problems ...
3
votes
2answers
2k views

Swift 3 Generic fetch request extension

I implemented an extension for the NSManagedObjectContext that takes any CoreData class as a parameter and performs a fetch request on it. I am new to CoreData ...
3
votes
1answer
7k views

Displaying JSON data from a server in a UICollectionView

This code pulls JSON from a server and delivers some data like imageURL, titleString and ...
3
votes
2answers
669 views

LeetCode Counting Bits in Swift

I solve this problem in Swift. I am looking for a code review, thanks! Given a non negative integer number num. For every numbers i in the range 0 ≤ i ≤ num calculate the number of 1's in their ...
3
votes
2answers
225 views

A generic AVL tree with SequenceType, CollectionType and ArrayLiteralConvertible extensions

I'm learning Swift and trying get a good understanding of some of its many features. The following is an AVL tree implementation with extensions that conform to ...
3
votes
3answers
453 views

Calculate the sum of all primes less than 2,000,000 in Swift

This is a Swift program I wrote to calculate the sum of primes below 2 million, but it is tediously slow. I am curious about what makes it so slow. My theory is that copying the filtered array is ...
3
votes
1answer
765 views

Tracking a geolocation

I have created this ViewController using Swift. Its job is to track geolocation and draw a line on a map and save it to core data object. I just want some advice on ...
3
votes
1answer
789 views

Building Weather Forecast from JSON with optionals

I am looking for the best way of parsing JSON in Swift 2.0. I have this JSON ...
3
votes
1answer
3k views

Set a font for a UITextView if the font is nil or not equal to desired font

Main question I am setting a font for a UITextView that is a subview in a custom view. I only set it if the user didn't specify the font size in the Interface Builder. I have the following working ...
3
votes
1answer
4k views

Draw an arc based on a given percentage

I wanted to create a class that would allow me to draw an arc representing a percentage of progress, similar to the activity view on the Apple watch. There are various examples which I found helpful ...
3
votes
1answer
1k views

Images viewer from URLs with download progress

I've created an imageViewer that will be initialized with a String array, and will download and show the images as needed. Alongside a review, could you give me a ...
3
votes
1answer
120 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 ...
3
votes
1answer
170 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....
3
votes
2answers
124 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 ...
3
votes
2answers
263 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
67 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....
3
votes
2answers
2k views

Comparing strings, ignoring case, punctuation, and whitespace

I have built a search function that will compare strings regardless of punctuation and whitespace. It is case insensitive. Here is my current function: ...
3
votes
1answer
229 views

Implementation of a piece table in Swift

I have implemented a piece table in Swift, based on a Javascript implementation. I don't have much experience with Swift yet, so I'm especially interested if I'm doing things "the Swift way". Any ...
3
votes
1answer
954 views

XCTestCase#waitFalseExpectationUntilTimeout implementation

I am working on an iOS project and I'm in charge of testing most parts of it. As I write some tests, I often have the need to wait for an asynchronous method to finish, and then test that something ...
3
votes
1answer
153 views

Constraints for auto layout

I am adding some constraints for my auto layout. My method calling the methods creating the constraints: ...
3
votes
1answer
88 views

Save total number of attempts NSDefault

I'm very new to Swift and programming in general. I'm creating a quiz application and am trying to create a function that will save the number of times a user has completed a quiz. It appears to work ...
3
votes
1answer
92 views

Managing a wish list from an API

I have a class that I use to manage a list to/from an API in Swift. Using a clean code approach, I'm wondering if, how, and why I should change it when I have a class that uses it for just one or two ...
3
votes
1answer
1k views
3
votes
1answer
56 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 ...
3
votes
1answer
47 views

Generic Fenwick Tree

A Fenwick Tree, or a Binary Indexed tree, is an interesting data structure that can efficiently update its elements. You can read more about it in this paper. Here is a generic implementation of a ...
3
votes
1answer
58 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 ...
3
votes
1answer
72 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 ...
3
votes
1answer
114 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 ...
3
votes
1answer
161 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 ...
3
votes
1answer
134 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
131 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 ...
3
votes
1answer
140 views

Custom caching class in Swift

I'm using Swift 4.0 and I'm using UserDefaults in my project for storing Strings like login or something. I have a class: ...
3
votes
1answer
381 views

Adding dragging ability to a UIView using UIKitDynamics

I recently published an iOS control/component called BJDraggable which basically, with a call of a method, enables us to drag a view within its superview boundary. ...
3
votes
1answer
269 views

NSLog-like logging framework for iOS

I am writing a logging framework for iOS. The idea is to create a behavior similar to NSLog to print the log message and some metadata to the console. The ...
3
votes
1answer
185 views

Symbolic derivative in Swift

I just wrote my first Swift program! It is a little computer algebra test that computes the nth derivative of the symbolic expression \$x^x\$. I chose this example because I'm keen to see how ARC will ...
3
votes
1answer
205 views

Sorting a list of phone numbers by teleconference provider and location

I'm looking to order an array of phone numbers with a primary sorting criteria of whether the teleconference provider is correct and a secondary criteria of whether the the location of the phone ...
3
votes
1answer
444 views

Checking whether strings are permutations of each other in Swift

I'm solving this problem on Hacker Earth, just for practice. The exercise is to determine whether two given equal-length strings are permutations of each other. Except for this one test case, which ...
3
votes
1answer
1k views

Basic Caesar Cipher in Swift 3.1

I have been learning Swift for the past day and thought I'd try a basic problem where I can do String manipulation. I am only on pg.100 of the Swift Programming Language on iBooks. Compared to python ...
3
votes
1answer
89 views

Optimal custom operator with generic type constraint for numerical type

I'm implementing (for an article) two custom infix operators: ¿% - to calculate percent of total %? - to calculate the percent ...
3
votes
2answers
1k views

Supporting different orientation in viewcontrollers

will you please give your thoughts (code review) on these two way of solving orientation. About the app: We have a universal App. The main purpose of the app is to watch the videos. The app has four ...
3
votes
1answer
309 views

Creating an area graph in iOS

I am trying to create an area graph from the upper and lower limit values. First I created two line graph from those points as: Sample data points are: ...
3
votes
2answers
122 views

Registering Pokémon weaknesses

I recently answered a question that had me wondering if I could simplify this below code without creating an extra function: ...
3
votes
1answer
1k views

Swift Hackerrank 2D Array

I solved this question in Swift, but was wondering if there is a better way or if my code can be improved: Given a 6x6 2D Array: ...
3
votes
1answer
579 views

Queue class with enqueue and dequeue

I am just learning swift and tried to make a queue class with enqueue and dequeue. The node holds the data for each element The enqueue adds an element to the "queue" The dequeue deletes the first ...