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
4
votes
2answers
159 views

Initializing an Array of Alternating Values

My goal in this project is to make something that can—as, quickly, effectively, and efficiently as Array(repeating: , count: )—initialize an ...
6
votes
1answer
84 views

Downset calculation code

I'm looking to port a Python script I have over to Swift, partly for some performance benefits, and partly to dip my toe into a new language. My program computes what is called the downset of a ...
4
votes
1answer
173 views

iOS Swift 3 app that requests data from the Stack Exchange API

This is my first Swift app, so I want to improve everything that I can about my code and know what I can do better. The app requests 10 developers from StackExchange API and displays them in a table ...
8
votes
1answer
1k views

Prime Number Generator in Swift

I would like to make (or improve my function) a function that returns an array of integers containing all the prime numbers from 2...n that can execute as quickly ...
5
votes
1answer
5k views

Grouping Date Objects by year and month

I have an array of date objects, which I want to group by year and month. The data structure I have chosen for my target is an array of arrays of Date objects. Two Date objects should be in the same ...
3
votes
0answers
46 views

Deck Downloader [closed]

This is my struct: ...
3
votes
1answer
195 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 ...
2
votes
1answer
4k views

Remove duplicates from array of non-equatable objects

I have an array of non-Equatable objects. I want to remove all the duplicates from the array. ...
1
vote
2answers
264 views

UserDefaults - defaults…?

I made this generic class which helps me reading values from user defaults. Besides it abusing several UserDefaults... what do you see? Can I make some instances ...
2
votes
1answer
76 views

Classes for representing teleconferencing numbers

I'm developing an app that joins tele-conference calls so we use conference numbers a lot. I've got this basic structure to encapsulate the information regarding a conference number. ...
3
votes
1answer
180 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
264 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 ...
0
votes
1answer
9k views

Prevent a UITextField from being input with aphabetic characters

The goal is to disallow typing alphabetic characters as input in a UITextField. Please tell me if this approach is convenient. ...
2
votes
1answer
75 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 ...
0
votes
1answer
75 views

Efficiently structuring data with protocol oriented approach in Swift

I need to integrate some server API calling in which I'm likely to get response as: ...
5
votes
1answer
235 views

Swift function to interpret Roman numerals (ported from JavaScript)

I have written some Swift for the first time, being competent enough in Javascript and having some experience in Ruby and Python. For my education, I've written a function that parses a roman numeral ...
3
votes
1answer
74 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 ...
1
vote
0answers
2k views

Swift/iOS component for label with clickable text buttons

So I'm creating a component based on UILabel, which I'm calling RichLabel. The main goal is to add support for clickable links (...
1
vote
2answers
1k views

Observable implementation

I have implemented a simple Observable class. I think that there is still room for improvement. Especially the fact that I have separate array to observe results ...
2
votes
1answer
544 views

Sums for list of ranges (CodeFights Basic Skills)

I can solve this problem with a brute force naive solution, but need to optimize it for time. I'm not in school, but trying to learn fundamentals on my own. I know I need to store the sum of the ...
2
votes
1answer
377 views

Fed Singleton struct class from plist

I have a plist file which has URLs in it and struct class is feeding from this plist. This struct class has static variable which I use to reach URLs in every part of the app. My question is that I'm ...
1
vote
1answer
883 views

Swift/iOS: Subclassing UILabel and setting properties

I'm writing this subclass to add an icon to a UILabel. It works, but I'm wondering if this is the best/cleanest way to do it. Do you see any improvements? Should maybe ...
1
vote
1answer
81 views

Emit different text and sound when each of three buttons is pressed

I would like to use this same code on multiple pages of photos (to help my son recognize people). So instead of reinserting the name of each person, I created the ...
1
vote
2answers
76 views

Performing a sum with Swift

I wrote the following in Swift to perform a sum: let total:Double = session.courses.reduce(0) { $0 + $1.totalPrice() } It's concise, it does the job but it does ...
2
votes
1answer
746 views

iOS Set game implementation

So I'm working through a MOOC, Stanford's "Developing iOS 11 Apps with Swift", and in the course the professor highly emphasizes how important it is to separate your View from your Model in the MVC ...
2
votes
1answer
212 views

Relative Strength Index

I am calculating a relative strength index. I took the calculations quite literally so I am sure everything's correct but now it is time to optimize the code and take it down to fewer variables. The ...
1
vote
0answers
707 views

Trimming a video, keeping quality

I am trimming an existing (stored in my gallery) video into smaller chunks; but I find the resulting video quality to be too degraded. ...
8
votes
1answer
1k views

Fibonacci in linear time by using an extra pointer

I have a function to find the nth number in a Fibonacci sequence, in which I am recursively calling the function. The sum is stored in a class variable and I have an extra pointer I increment every ...
1
vote
0answers
20 views

ManuallyCompletableOperation for OperationQueue

Here is a very handy subclass of Operation that allows to do asynchronous tasks inside an OperationQueue: ...
2
votes
1answer
213 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
180 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 ...
2
votes
1answer
2k views

Create a view with a thick inner border that has a gradient

InnerGradientBorderView is a subclass of UIView that has a thick border with a gradient. I have tried to replicate the Zoom ...
2
votes
2answers
267 views

Unit test for a password-change request

I'm studying unit testing in swift and I would like to know if I'm doing the right way. Here I have the model ...
1
vote
0answers
89 views

UIImageView Animation with duration change

I have an array of UIImages that I animating using UIImageView, and creates an effect of wave. the user have plus and minus ...
2
votes
2answers
530 views

Console Based Snake Game

This is a simple program where the goal is to visualize a virtual game to be played by an AI. For the purposes of this post, the playGameManually() function was ...
1
vote
1answer
47 views

Error handling Beacon scanning

I've recently began trying to put more error handling in to my code so I thought I'd post a use-case to check I'm on the right path. I feel like this is going to make my functions much larger and more ...
2
votes
1answer
147 views

HackerRank Caesar Cipher, not using map, filter, reduce, regex

Julius Caesar protected his confidential information by encrypting it in a cipher. Caesar's cipher rotated every letter in a string by a fixed number, K, making it ...
2
votes
1answer
692 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): ...
1
vote
2answers
596 views

iOS tableView with two special rows of headers

Using swift for iOS, here is my cellforRow method ...
1
vote
1answer
65 views

SKAction on SKLabel with array of Strings

I have an SKLabel attached to a parent SKNode and an array of strings: ...
1
vote
3answers
134 views

Navigation controller in Swift

I was looking for a way to write this code shorter and still get the same result. Can this be achieved? ...
1
vote
2answers
100 views

Boolean array, NAND of [SKSpritenodes]

I'm using spritekit, using on touch to detect what the users has tapped, ie., no collisions, etc. I have an array of sprite nodes which in effect is a multi-state boolean switch for now the user ...
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 ...
1
vote
1answer
2k views

Extension for grouping array into two dimensional array based on element ([] -> [[]])

I'm new at generics, but I've written an array extension to group an array by array element into a two dimensional array: ...
1
vote
1answer
374 views

Create new UIImage each time or once

I am writing a control that has a toggle on (show/hide password). The UITextfield has a UIImageView in that acts as the toggle. ...
1
vote
0answers
1k views

Upload multiple photos to server

I am uploading an array of photos to the server (using Alamofire): ...
3
votes
0answers
492 views

Applying Gaussian blur to UILabel

Here is the code and it is really slow, like seconds slow to render about 25 labels. ...
11
votes
2answers
2k views

Computing the integer square root of large numbers

The "integer square root" of a non-negative integer \$ n \$ is defined as the largest integer not greater than \$ \sqrt{n} \$: $$ \operatorname{isqrt}(n) = \lfloor \sqrt{n} \rfloor = \max \{ k \in \...
2
votes
1answer
190 views

Toggle case of a string in Swift

What is benefit of using uppercased() / lowercased() over the following approach ? (Other than making it more readable) Any ...