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
4
votes
1answer
190 views

Optimize Data Sending/Querying to Parse Swift iOS

I have a swift method that I'm using to update Parse in the backend when the button is tapped. Votes are being updated: The method acts as a voting system, incrementing a label every time it's tapped. ...
4
votes
1answer
5k views

Basic expressive Swift background thread execution

I created a basic background thread class in swift to replace the ugliness of: ...
4
votes
0answers
33 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 ...
4
votes
0answers
77 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 ...
4
votes
0answers
7k views

Page and center UICollectionView like App Store

I need a collection view to page through cells and center it like the App Store, where a portion of the previous and next cells look like this: The native ...
4
votes
0answers
560 views

Update UI once all API calls are done

I'm learning Swift at the moment but I would like to produce well-organised code. The goal of my little app is to display the weather of my current location. I use : the API of Darksky : https://...
4
votes
0answers
85 views

Swift framework that facilitates making atomic changes to several objects at a time

For the purposes of an app I work on I have created a separate framework that abstracts away the mechanism of making atomic changes to the complex object structures. Each class that has to ...
4
votes
0answers
337 views

Unit Testing Against Exceptions

I am writing a Swift library. I'm writing unit tests for that library. I am afraid that some of the code that I am testing will possibly throw exceptions. In Swift, we can handle errors, but we can ...
4
votes
0answers
228 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
3
votes
2answers
4k views

Music player in Swift

I made a simple mp3 player that plays, pauses and stops a given song, shows the time elapsed, and has a volume control. I read the documentation and can't figure out the difference between the ...
3
votes
3answers
829 views

Creating an array of objects for dictionaries

I wrote a piece of code that creates an array of objects based on the array of dictionaries. The problem is that my solution uses multiple loops imperatively. Let's consider the following case. There ...
3
votes
2answers
761 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 ...
3
votes
3answers
6k views

Swift format string with separator every n characters where n changes

In Swift I have a string where a dash needs to be inserted after every 3 characters, if there are 4 characters or 2 characters at the end of the string they should be shown as "-xx-xx" or "-xx" ...
3
votes
1answer
1k views

removeAll(closure) in Swift

From this library I wrote, I have created this function in Swift, but I'm not happy with the implementation. Can anyone suggest a better way to do this? I really don't like changing counters inside <...
3
votes
1answer
175 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 O(...
3
votes
1answer
255 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 ...
3
votes
2answers
2k views

Counting neighbor cells of a matrix

I was given this problem to solve inside a Swift playground. I was vaguely told my answer is correct but not good enough. ...
3
votes
2answers
78 views

Uploading photos of various sizes

In my solution I've implemented transaction-like methods of uploading posts media. For example I'm adding new post with photo. I want to have 700x700, 200x200, 70x70, 10x10 px sizes in my storage and ...
3
votes
2answers
1k views

Efficient way in Swift to trim an array

Let's say I have a struct… struct Person { let isMale: Bool let name: String } and an array of Person structs. I want ...
3
votes
2answers
2k views

UIButton Subclass - Overriding getters to return placeholder/default values

I'm in the process of converting a custom UIButton from Objective-C to Swift which has custom properties and default values for those properties: MyButton.h ...
3
votes
1answer
166 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 ...
3
votes
1answer
893 views

Custom map annotations and clusters

I registered a CustomMapAnnotationView and a ClusterView: the first one simply extends ...
3
votes
2answers
749 views

Swift permutations of the digits of an Integer

I want to return all of the permutations of an integer in Swift. ...
3
votes
1answer
273 views

Wrapping the iOS triple buffering procedure in a generic swift class

In the Metal sample code and best practices guides it is advised to use a triple buffering technique to avoid access conflicts between the cpu and the gpu. The required code to do so requires ...
3
votes
1answer
444 views

Singleton class with custom initializer

In a Swift project, I have a class should be used as a singleton: ...
3
votes
1answer
471 views

Implementing joinWithSeparator on a Character array

I recently answered a Stack Overflow question about transforming an array of Characters into a String in Swift. Looking at the question and the Swift standard lib, it appears that there is a method <...
3
votes
2answers
117 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 ...
3
votes
1answer
389 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
219 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
77 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
2answers
4k 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
20k 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
1answer
8k 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
878 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
231 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
489 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
815 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
797 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
2answers
208 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
178 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
253 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
345 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
75 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
1answer
252 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
89 views

Crap (from the Past) Scraper

I listen to a podcast called Crap from the Past. It's a radio show that airs weekly in Minneapolis and specializes in playing music from my childhood. The show has been on the air for ~26 years. I ...
3
votes
1answer
906 views

Parse heterogenous JSON array

I need to parse a JSON generated by iTunes Search API. I'm looking for all apps by a certain developer, and I usually get a response like this (simplified): ...
3
votes
2answers
3k 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: ...

1
3 4
5
6 7
13