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
77 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
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: ...
1
vote
0answers
358 views

VIPER Architecture

I write Swift and architect apps mostly based on VIPER pattern. The thing I always wonder is, is it a proper to store some temporal values in Interactor? Let me ...
4
votes
1answer
8k views

Creating a array of custom objects from JSON, sent using PHP from a MySQL database

I'm using PHP to send data in JSON to create an array of custom objects in Swift. I've been told retrieveData() is bad code because it's in an infinite loop. I'm ...
0
votes
1answer
330 views

Simple networking layer in Swift using Strategy design pattern

Does the following code demonstrate proper use of Strategy design pattern for a simple networking layer in swift 3? Some code smells I'm unsure about: violates Single responsibiility principle. ...
3
votes
1answer
301 views

Fetch nearby chat users using Firebase and nested completion handlers

I have a method that calls three functions that each make a request to Firebase and pass back data in a completion handler. Once the data from 2 of the completion handlers is sent back, I call another ...
4
votes
0answers
81 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 ...
40
votes
0answers
804 views

Swiftly turning wheels – The May 2017 Community Challenge

This is my attempt at the May 2017 Community Challenge in Swift, with a chain consisting of rigid links. I took this as an opportunity to learn SpriteKit, Apple's framework for 2D games. At least ...
1
vote
0answers
774 views

RxSwift iOS Observable FIFO Queue Implementation in Swift 2

I am trying to develop an Observable queue that executes given Observable chains one at a time. The code will be used to encode videos on an iPhone and only one queue will be needed per launch, ...
1
vote
1answer
319 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: ...
2
votes
0answers
702 views

REST API wrapper class with Alamofire + Gloss

I have come up with this structure to handle API calls using Alamofire + Gloss. The multipart method I came up with was kind of in a hurry, it works but I think it could be done much better. So this ...
6
votes
2answers
281 views

Password generator class

I've written this class to generate a random password and was wondering if there's anything I could improve upon here and whether or not this a safe (most random) method of generating a password. ...
1
vote
0answers
161 views

Multi-Context CoreData Implementation

I'm using Mulit-Context CoreData for Asynchronous Saving, which follows this architecture: Here is code stack: ...
2
votes
0answers
98 views

Private contexts and their parents in CoreData

I find myself following this pattern a lot in my core data code, which works, but I'm wondering if it is needed... ...
2
votes
1answer
603 views

Set a UITableViewAccessoryType in a single UITableViewController used for two different purposes

I have a UITableViewController that displays a list of lift names (think weightlifting) and it's used for two different things. It can be accessed from view A to select a lift that will be saved as a ...
1
vote
1answer
834 views

Styling navigationController per viewController

The design of my application consists of multiple viewControllers which all have different styling applied to them. The following code is used in every viewController to style the viewController: <...
3
votes
0answers
103 views

Load data from WebAPI to the ViewController

My current code working perfectly, it is for data load from web api to the UIViewController (UITableView). But I am confused ...
13
votes
1answer
970 views

Interview coding challenge for iOS Part 2 - the application in Objective-C and Swift

I recently interviewed with a company that needed a C/C++ programmer to work on the iOS side of the products. The job description indicated they needed someone with 4 years of Objective-C and iOS ...
5
votes
1answer
434 views

Neural Network in Swift

This is my first Neural Network, specifically a multilayer feed forward neural network that uses back-propagation for training, and I plan on using it for a multitude of projects. I started with the ...
6
votes
1answer
1k views

Simple Tip Calculator

This is something I put together recently, and I thought I would see if anyone had any recommendations for modification of this short implementation of a tip calculator. The calculator uses a ...
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 ...
4
votes
1answer
290 views

Notify user of credential failure and make another attempt

The below code works because of the do operator on line 24. Is there a more functional way to get the test to pass, or would you consider this an appropriate use of ...
1
vote
1answer
1k views

Draw grid programatically with borders

I need to draw a grid with some special requirements. My current solution is working but is far away from ideal I guess. Attached you can find the current working solution: Some of my thoughts which ...
1
vote
1answer
955 views

UIViewController without interfacebuilder

I have a template I've been using with Swift for UIViewController and UIView subclasses without a ...
4
votes
1answer
417 views

Writing a chunk of a file to a socket in Swift

I'm writing a chunk of a file from an offset to a socket. This is my implementation and it's working OK from my tests. Any comments or speed improvements? ...
1
vote
0answers
2k views

Paging loader using RxSwift

This is generic logic for handling network requests that load data based on pages. It is assumed that the view controller would implement the UISource protocol. I ...
2
votes
0answers
197 views

Find MIDI devices with certain names and make them usable

I'm working on a Swift app for macOS, where I take input from MIDI devices and transform that input. The MIDI devices being supported come in for flavors. What my code does is scan for MIDI devices, ...
4
votes
1answer
175 views

Convert String to Integer (calculator app)

I'm currently learning Swift and today I created my first application, a simple calculator. My main goal was to practice and create something without any help. After a few hours my application was ...
4
votes
1answer
5k views

Countdown timer in every table cell

I am making countdown app with multiple records, so I am using UITableView to show that records and countdown dates. What I do is just take one timer and reload cells on every second. Is this a best ...
1
vote
1answer
448 views

Read JSON as a dictionary of country codes and names

For a small system I need the Country Code mapped to the country name (e.g. "GB"-> "United Kingdom"). To accomplish that I read a JSON file and save it to a dictionary using swiftyJSON. Is there a ...
4
votes
1answer
67 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 ...
3
votes
3answers
4k 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" ...
0
votes
1answer
61 views

Parser to extract calendar data

I'm wondering how I can improve this class, for instance: Should local variables such as allInput that are passed in to more than one function be instance ...
4
votes
1answer
2k views

Finding consecutive days in an array of dates

The problem: How to get the largest number of consecutive days from an array of unknown number of Date objects, by taking into account days only like 4th of April, 5th of April and so on. Example ...
-1
votes
1answer
82 views

Can this Swift code be simplified?

...
1
vote
1answer
35 views

Making a TableViewDataSource more independent of the data it utilizes

I have written an ordinary tableView to display a list of players, with the following data structure that's in place. A Conductor (which is the user), has many <...
10
votes
1answer
318 views

Sequence-based enumeration of permutations in lexicographic order

This is follow-up on On Knuth's "Algorithm L" to generate permutations in lexicographic order, where I presented the following method to enumerate all permutations of array elements in ...
14
votes
3answers
2k views

On Knuth's “Algorithm L” to generate permutations in lexicographic order

I needed a method to generate all permutations of given elements, so I decided to implement "Algorithm L (Lexicographic permutation generation)" from Donald E. Knuth, "GENERATING ALL PERMUTATIONS" in ...
6
votes
1answer
4k views

UIButton subclass with animated 'shimmer' effect

In earlier versions of iOS the lock screen had a 'slide to unlock' element which I'm referencing as a 'shimmer' effect. The effect I'm looking for is simpler: Button starts with single color (e.g. ...
5
votes
2answers
325 views

Practical number algorithm

I am trying to write a program to find the practical numbers, from an input from \$1\$ to \$n\$. Practical numbers My code is running correctly but it is extremely slow when calculating numbers ...
2
votes
1answer
135 views

REST API client

I am new in iOS development and Swift. I am going to develop a simple application which communicates with external REST services. This is my first experiment. I appreciate feedback on best ...
2
votes
1answer
939 views

Implementing delegate methods in an UIView class

This is my UIView class: ...
2
votes
2answers
130 views

Loading data from a web API to be displayed in a tableview

In my object Dish xxx.Dish, I want to access the Choice class price and name to display . ...
5
votes
1answer
3k views

Swift 3 UIPicker

I have been making a little test app to try and learn Swift 3 / iOS better. I started a while ago with with Swift 2 but stopped, so getting back into it, but there is so much iOS to learn! It seems ...
8
votes
4answers
1k views

Project Euler problem 14 (longest Collatz sequence) in Swift 3

I was trying to solve Project Euler:Problem 14 using Swift 3, but it takes ages to give me an answer, which is a sign that my code is absolute garbage performance-wise. What could I do to increase the ...
2
votes
1answer
169 views

Amplitude and Frequencies of sound Analyser

As I'm beginner with mobile/OO programming, I reached a situation that confused me and made me wonder if I was coding correctly... The main class: ...
1
vote
1answer
326 views

Generic array flattening function

With help from the codereview community, I've written a function to flatten a generic nested array. I have it written several ways but want to focus on the following implementation: ...
2
votes
1answer
133 views

CommandLine StreamFormatTester

Using Chris Adamson's book Learning Core Audio I'm getting familiar with Core Audio for Mac/iOS. The code examples are 100% Objective-C. I'm trying to follow along using Swift 3. This small piece of ...
2
votes
2answers
855 views

Swift HackerRank Missing Numbers Challenge

I'm attempting to solve the "Missing Numbers" challenge on HackerRank where I'm tasked with finding missing elements comparing two arrays. Foundation's ...
1
vote
0answers
202 views

Cookie Clicker esque game idea

I am making a cookie clicker type game as a small project, within Xcode, written in Swift. I have a been developing a function which will turn a Int64() into a 4 ...