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
2
votes
0answers
97 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
591 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
813 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 ...
9
votes
0answers
896 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
433 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
2k 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
925 views

UIViewController without interfacebuilder

I have a template I've been using with Swift for UIViewController and UIView subclasses without a ...
4
votes
1answer
412 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
1k 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
181 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
442 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 <...
9
votes
1answer
303 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
318 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
896 views

Implementing delegate methods in an UIView class

This is my UIView class: ...
2
votes
2answers
129 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
166 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
325 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
131 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
814 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 ...
2
votes
1answer
525 views

Extract index of first unique element in large array in Swift

I'm using the following code to return the first index of a unique character in a large String. It works fine until I get to large strings, where it times out. Is ...
2
votes
1answer
7k views

Remove Duplicates from Array in Swift 3.0

I ran the following code through a Leetcode.com challenge and it says the runtime for the test cases is 119ms, which puts it at the back of the pack performance wise. The goal is to remove duplicates ...
1
vote
1answer
2k views

Showing segue after button action

I have an iOS Swift app with 8 buttons that call the same segue, but this is very repetitive. How can I refactor so it uses the same function prepare? ...
8
votes
6answers
2k views

DFT (Discrete Fourier Transform) Algorithm in Swift

I am looking to replicate in Swift what the FFT function does in Matlab. Essentially, it takes an arbitrary length signal (not necessarily a multiple of \$2^n\$) and gives real and complex DFT ...
2
votes
1answer
125 views

Convert ISBN10 to ISBN13

Looking to confirm that I am doing this in the most efficient way. ...
1
vote
0answers
569 views

Mocking protocol with class/static functions in Swift

I am using one of the open-source Objective-C keychain wrappers to store data in iOS keychain. For test cases, I have created protocol as: ...
4
votes
2answers
1k views

Parsing and converting DMS Coordinates from String to Double

I have some coordinates looking like N47° 15' 36.75",E011° 20' 38.28",+001906.00 and I've created a class to parse and convert them to Double: ...
9
votes
1answer
3k views

Mocking UserDefaults in Swift

In my application, I am using UserDefaults to save some data. I also started writing tests for testing my application code. At one place I stuck where I wanted to ...
6
votes
2answers
234 views

Project Euler solution #2 using Swift 3

I just wanted some review and opinions. Any better implementations or suggestions would be great. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...
6
votes
0answers
380 views

Swift class to check ApplePencil reachability

I've implemented a class that lets you check out whether there is an ApplePencil connected to the device or not. ...
1
vote
0answers
172 views

XMPP XML Parsing and Tests in Swift

I am implementing chat app using XMPP. Here is my XML Parser function which tells me whether given XML is file transfer offer or not: XMPPIQ+FileTransfer Extension-> ...
3
votes
0answers
400 views

Posting iOS notifications from sender or from receiver

In Swift, should I be posting notifications to the iOS notification center from the device sending a text message or from the device receiving it? I'm using ...
3
votes
1answer
3k views

iOS Core Data Model with Swifty JSON

I have been using SwiftyJSON to create my models of Object in Swift. But recently, I moved to CoreData for saving the objects locally. I am new to CoreData and want to know the best practices I should ...