The Stack Overflow podcast is back! Listen to an interview with our new CEO.

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
5
votes
2answers
149 views

Splitting an amount of money equally between a group of people

I'm building a clone banking app at the moment, and one of the things I'm trying to do is add Split Transaction (which can then be shared with a set of friends paying a given amount each). Initially, ...
5
votes
1answer
212 views

Message factory

Today I thought about Factory Design Pattern in Swift, and I do an implementation with Extension. My post is about if anyone have any observation or issue about this implementation violate any ...
5
votes
2answers
1k views

Counting words from standard input in Swift

I know Swift isn't exactly meant to be used to write your classic stdin to stdout scripts, and that Python, Ruby, Perl, bash, awk, and friends are much better in this area, but I'd still like to see ...
5
votes
1answer
4k 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 <...
5
votes
1answer
334 views

Classification tree in Swift

As an effort to teach myself Swift as well as to get familiar with machine learning algorithms, I've been trying to implement common algorithms, starting with a Random Forest. This is, for the moment ...
5
votes
1answer
3k views

Implementing the Hashable Protocol in Swift with the DJB hash function

A while back I made a custom String struct (see github repo) because of the difficulties in dealing with Mongolian Unicode rendering when using Swift String or <...
5
votes
2answers
338 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 ...
5
votes
3answers
809 views

Loading Configurations from plist into singleton

In my iOS application, I've created a singleton class that reads a configuration plist file and provides accessor methods to easily retrieve the values: ...
5
votes
1answer
229 views

Project Euler, Challenge #12 in Swift

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, 21, ...
5
votes
1answer
1k views

Calculating delta in SpriteKit using Swift

I am attempting to learn swift by refactoring one of my old games and I need to rewrite my update method which calculates a delta time. This code works but is ugly. ...
5
votes
1answer
55 views

Enum for handling network request errors in Swift

I'm working on a new API written in Swift 5 and I wanted to play with the new Result. I wanted to know what you guys think about this syntax: ...
5
votes
1answer
6k 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 ...
5
votes
1answer
252 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 ...
5
votes
1answer
10k views

Get a specific value from a big JSON response

I have this code to access travel time from the Google directions api JSON result: ...
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 ...
5
votes
2answers
4k views

Tic Tac Toe in Swift

Any feedback encouraged. My checkForWinner function feels cumbersome to me. ...
5
votes
1answer
304 views

Sierpinski Triangle

I am a Java programmer who recently started learning some Swift. I made an app that displays the Sierpinski triangle and adds triangles if the user pans up, and zooms in and out using the pinch ...
5
votes
1answer
578 views

Avoiding callback chaining in authenticator

I'm developing an iOS Application in Swift that uses Google Cloud Endpoints as its backend. For now, I've just written the code for the user to login with his Gmail account and I've refactored it as ...
5
votes
1answer
619 views

Showing a certain screen depending on a particular status

In this iOS app I'm working on, there are two landing screens shown to the user depending on a particular status. The screens are Login screen and Activate screen. Let me explain what this Activate ...
5
votes
1answer
967 views

Usability of this Observable class

I created an Observable class that allows me to subscribe to a wrapped value. The implementation looks like this: ...
5
votes
1answer
179 views

Networking structure for Swift iOS app

I would like any constructive comments regarding the structure of this simple App that takes an API response and then displays on a table view. The URL is written in a ConstantsAPI file ...
5
votes
1answer
231 views

Dijkstra algorithm implementation in Swift

I've implemented Dijkstra's algorithm to find the minimum path between two nodes. ...
5
votes
2answers
81 views

Time manipulation for notification reminders

I'm new to programming, Stack Overflow and Code Review. I was encouraged to post this method here based on a question I posted on StackOverflow here. Let me know if you have tips for improving this ...
5
votes
1answer
1k views

Weighted Probability Problem in Swift

I was asked a weighted probability question in a technical interview a few months ago that went something like this: Given an input of colors and an integer "weight" value, randomly return a color ...
5
votes
1answer
3k views

Canonical Implementation for a Concurrent Subclass of NSOperation in Swift 2

I would like to develop a kind of template or canonical implementation for a concurrent subclass of NSOperation in Swift. See here for my previous request which is implemented in Objective-C. In that ...
5
votes
1answer
4k views

Checking network status

I have this slightly popular Swift library called IJReachability up on Github. It checks the network connection status. Due to my office workload I've been very busy in the past few months so I couldn'...
5
votes
1answer
8k views

Swift project using PHP web service

I was hoping for someone to review my current project, which was created in Swift and uses a PHP web service. I'm not worried about UI elements, as this is just a 'test' project, but I'm concerned ...
5
votes
1answer
2k views

Closure as UIControlEvents handler

I'm expanding the functionality of this SO answer. Mainly I'm focusing on: You can add as many handlers as you want. You can remove (i.e. cancel) the handler. You can receive the ...
5
votes
1answer
852 views

Combining RAC signals and updating UI

I'm using Swift 2.1 and ReactiveCocoa 4.0.4 alpha 1. I'm combining multiple signals to enable a button based on if they have valid inputs. The following code works correctly, but I'm wondering if ...
5
votes
1answer
353 views

Parsing travel duration data

I'm trying to parse an estimated travel duration and distance between two waypoints using Google Directions API. Tap on this to see an example of data received. ...
5
votes
1answer
438 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 ...
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 ...
5
votes
1answer
415 views

Vertical-scrolling 2D platform game

I am working on a vertical-scrolling 2D platform game using GameplayKit, SpriteKit and I am writing it in Swift 2.0. Today I ...
5
votes
1answer
76 views

Draw a spark line with SwiftUI

I am using a set of data points (currently randomly generated), and drawing a line graph inside a box: ...
5
votes
0answers
78 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 ...
5
votes
0answers
2k views

Reducing complexity in NSView event handling code in Swift

My Cocoa event code always tends to descend into madness, I need to advice on how to reduce complexity. I've spend a few hours putting this example together. CanvasView is a layer hosting subclass of ...
5
votes
1answer
2k views

Road to MVC: the case of Settings Table View Controller

Now that I know that MVC can help do better code, I want to make my SettingsTableViewController class conform to it. ...
4
votes
2answers
153 views

Finding a perfect square smaller than an input number (Swift)

This code runs slowly, even with numbers smaller than 1,000,000. Can someone help me optimize this thing? ...
4
votes
1answer
133 views

“What To Do” App

I am starting to build up my portfolio, so I am starting to build projects whenever an idea pops up in my head. So, I decided to build an app that helps you decide what to do. Basically how it works ...
4
votes
2answers
6k views

Removing a subview with a subview from a UIView without memory leaks

I made a custom UITextView for vertical Mongolian writing. It is made by subclassing UIView, which has a subview called ...
4
votes
2answers
55 views

Reducing a list of points into a list of pairs of points

I have some data… let points = [(718, 620), (4596, 1280), (410, 333), (4597, 993), (410, 337), (4597, 996), (428, 337), (4597, 1000), (431, 335), (4599, 1044)] …...
4
votes
2answers
99 views

Swift main thread style

I run into issues where I forget to run UI changes on the main thread. I've just fixed an issue for loading and unloading an activity indicator and fixed it with the following code: ...
4
votes
2answers
131 views

Translating Objective-C use of static and +(void)initialize to Swift

I am converting an old Objective-C class into Swift. My actual question is at the very end after all of the code. Here is a cut-down version of the Objective-C class: DateInfo.h: ...
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: ...
4
votes
1answer
10k views

Swift FloatingPoint rounded to places

I'm playing a bit with extensions for default protocols in Swift 3.0. I would like to implement rounded(toPlaces places: Int) -> Self for ...
4
votes
1answer
103 views

Safe init using failable guarded initializer

I am wondering if that is a safe and proper init, with one failable init guarded and an init. Are the force-unwrap correct in the self.init as I know they are ...
4
votes
2answers
5k views

Recursive function to show directions for multiple locations

I have a Mapview which shows a bunch of locations (Events). Here's the code of an Event object. ...
4
votes
1answer
903 views

Second attempt at Hangman in Swift

I recently posted my Hangman game, and got some amazing feedback! The main thing suggested was to create a word generator that could read JSON files so that my hangman brain class didn't have to ...
4
votes
2answers
185 views

Fetching the definition of a word using a REST API

This is the code I'm using to GET the definition of a word from Wordnik's REST API. I don't want to ignore any error but this is causing the code to be ridiculously long. I'm new to Swift so I'd ...
4
votes
1answer
770 views

Optimization of multiple arrays for filtering

My app will be running on an iPad with A7. I pass in 3 JSON arrays and right now do some simple filtering, in the future the operation will be much more complicated. I realize the ...