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
3
votes
1answer
218 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 ...
8
votes
2answers
452 views

Postponed Prime Sieve in Swift

Motivated by this question, I looked out for other "infinite prime generators", i.e. functions which produce the list of prime numbers in increasing order and do not have an a-priori upper limit (such ...
4
votes
1answer
806 views

Maintainable networking layer architecture

There are so many different solutions and examples on how to build a proper networking layer, but every app has different constraints, and design decisions are made based off trade-offs, leaving me ...
1
vote
1answer
416 views

Core-data object with relationships conforming protocol in swift

I have a situation where I have to use protocol to be conformed by NSManagedObject which has relationships with other entities. My protocol is like: ...
5
votes
1answer
1k views

Concatenating an array of optional NSAttributedStrings

Imagine you had to join together attributed strings with a separator in between them. Which of the following methods would you use? An extension on SequenceType with a function that takes in a ...
2
votes
0answers
108 views

Log in user through json and display the application

I am currently learning swift 4 and would like to ask you to correct my code. (I would like to have a pattern for learning the "beautiful code"). My code gets data from the server in JSON format and ...
6
votes
1answer
88 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
233 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 ...
6
votes
1answer
9k 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 ...
9
votes
1answer
2k views

Extending CGPoint to conform to Hashable

For Advent of Code Day 1, I found myself needing to use a tuple as a key in a dictionary. Seeing that I can't extend tuples in Swift, I decided to extend CGPoint ...
3
votes
1answer
889 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): ...
2
votes
1answer
894 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 ...
3
votes
0answers
46 views

Deck Downloader [closed]

This is my struct: ...
0
votes
2answers
2k views

UIAlertController and input validation

I'm refactoring some "old" Swift code using deprecated UIAlertView and delegates. I have a UIAlertController with an input ...
3
votes
1answer
379 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
7k 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. ...
5
votes
1answer
5k views

Chop off trailing newline for Swift's NSAttributedString

I've made this extension but I'm touchy around NSAttributedStrings, keenly aware that Swift refuses to use the traditional notion of integer lengths on Unicode <...
1
vote
2answers
413 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 ...
4
votes
2answers
16k views

Showing activity indicator (loading image) while processing in background

I have a login screen on my iOS app. When I click login button I want to make sure that user should be displayed a loading image in center of the screen. I found lots of different methods online but ...
2
votes
1answer
77 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
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
287 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
13k 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. ...
15
votes
4answers
3k views

Int extension for translating integer to plain English

This code was inspired by this question: Number to Words ...
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 ...
5
votes
0answers
80 views

Moves box in direction of touch, and has wraparound when reaching edge of screen

Part of me thinks that it would be simpler to ditch Apple's move API and just updated position with a timer. I know that's what I did with a JS canvas snake game I built a while ago. But I'm also ...
0
votes
1answer
98 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: ...
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
2answers
2k 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 ...
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 (...
5
votes
1answer
333 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
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 ...
2
votes
1answer
437 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
1k 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 ...
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 ...
1
vote
2answers
85 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
916 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 ...
4
votes
1answer
68 views

iOS game of drawing sticks with AI and scoring

My code actually works. I was just wondering if there was alternative ways, maybe even more efficient ways of coding my program. This is suppose to be a game of drawing stick, and it's recording the ...
2
votes
2answers
481 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 ...
3
votes
1answer
221 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
3k 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 ...
3
votes
1answer
102 views

Categorized Photo Albums

I was told the function "hompage" was too clunky to conveniently make a tableview. The cells will have the information in "PHOTO ALBUM ICONS" and "BUTTON ON TOP OF PHOTO ALBUM ICONS". ...
2
votes
1answer
252 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
1k 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 ...
7
votes
2answers
7k views

Core location background update and upload to server

I want to upload a user's location to a server to send them a location-sensitive alert, so the location needs to be fairly accurate: ...
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: ...
1
vote
2answers
173 views

Switching between queues in cellForIndexPath method

My tableView is scrolling very slowly because there is a fetch request done in every cellForIndexPath method. I have verified ...
1
vote
0answers
134 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 ...
1
vote
3answers
164 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
3 4
5
6 7
13