Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development.

learn more… | top users | synonyms

4
votes
0answers
10 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 ...
2
votes
0answers
19 views

“Extending” the Swift 2 ErrorType protocol

I am building a simple REST client in Swift 2. The methods the client offers can return errors. Every method returns the same errors (network problem, unauthorized, etc...). But each method can also ...
1
vote
0answers
27 views

Adding a constraint to a PFQuery on a PFRelation with objects that have already been gotten

Please read the following question that I asked regarding creating the following code. I was playing around with different combinations of whereKeys and queries, ...
6
votes
2answers
75 views

Background execution in iOS

The following class BackgroundExecutable is to be used to take a function f and return a function ...
4
votes
2answers
39 views

FizzBuzz in Swift 2

I saw this question: Is this FizzBuzz Swift-y? and I couldn't resist the temptation to attempt a Swift2 implementation: ...
1
vote
1answer
35 views

Retrieving creation date from Parse.com data

I got to show the createdAt date in a message timeline, I tried to make a separate array only for dates, but don't know if it is the right path to follow. It seems ...
3
votes
1answer
84 views

Building Weather Forecast from JSON with optionals

I am looking for the best way of parsing JSON in Swift 2.0. I have this JSON ...
2
votes
2answers
53 views

Project Euler, Challenge #17 in Swift

Number letter counts, Problem 17: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers ...
-1
votes
0answers
7 views

Swift Type vs explicitly unwrapped Type [migrated]

I just wanted to use the .map closure in Swift and stumbled upon this: ...
5
votes
1answer
117 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, ...
7
votes
3answers
1k views

Project Euler, Challenge #5 in Swift

The problem: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of ...
4
votes
1answer
74 views

ReactiveCocoa implementation of async function

I would like a review of the RAC implementation for the function setGist() I've posted the code on GitHub for easier reading. Description: You create an instance ...
2
votes
2answers
99 views

Load text file into an array in Swift

I'm drowning in Swift optionals and error handling syntax. I'm just converting a text file into an array of Strings. One would think that this could be a simple two or three liner but by the time I ...
3
votes
1answer
42 views

Set a font for a UITextView if the font is nil or not equal to desired font

Main question I am setting a font for a UITextView that is a subview in a custom view. I only set it if the user didn't specify the font size in the Interface Builder. I have the following working ...
3
votes
1answer
53 views

Switch statement for adding/removing operands to the text part of a label

I have a switch statement with five cases, and four of them are really similar to the others. How could I properly refactor this code to eliminate the duplication of code? ...
4
votes
2answers
159 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 ...
2
votes
2answers
72 views

Date formatters, lazily instantiated once

I would like to create two date formatters only on first call. In Objective-C I would use dispatch_once() but now working in Swift. Am I doing it correctly? My code ...
4
votes
2answers
134 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
67 views

Using Grand Central Dispatch to fetch data from Parse.com and update UI asynchronously

This works, and the UI is snappy in the simulator, but since this is my first time really using GCD, I'd just like this code to be reviewed before I start using it everywhere. Note that this is ...
3
votes
1answer
50 views

Constraints for auto layout

I am adding some constraints for my auto layout. My method calling the methods creating the constraints: ...
1
vote
0answers
40 views

Interactive transition between view controllers

I have made an interactive transition controller in Swift in two different ways. This interactive transition controller is the parent class and I have few child classes which adapt the parent for ...
3
votes
1answer
69 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 ...
3
votes
3answers
113 views

Creating an array of objects for dictionaries

I wrote a piece of code that creates an array of objects based on the array of dictionaries. The problem is that my solution uses multiple loops imperatively. Let's consider the following case. There ...
3
votes
1answer
66 views

Draw an arc based on a given percentage

I wanted to create a class that would allow me to draw an arc representing a percentage of progress, similar to the activity view on the Apple watch. There are various examples which I found helpful ...
10
votes
1answer
273 views

Stack implementation using Swift

I would like to request some code review and feedback on a stack implementation using Swift. Disclaimer: I might have not used protocols, optional unwrapping and error and ...
7
votes
1answer
65 views

Hangman in Swift

I am a Java programmer trying to learn the ways of Swift. I coded a Hangman game in Xcode. I was wondering what I could improve, specifically whether I used delegation correctly and if there is ...
3
votes
0answers
51 views

Second attempt at Sierpinski Triangle App

I am a Java programmer trying to learn the ways of Swift. A few days ago, I posted the code for a very simple app that draws a Sierpinski triangle and implements a pretty buggy zoom. I was told to ...
8
votes
1answer
106 views

Parse query checks and increments

In my app, the user can upvote a cycling track if they want to ride on it. Note: I do understand I can use a boolean column to check if a user has voted or not, but, I am just testing at the ...
1
vote
1answer
72 views

For Loop with Index to Functional

Trying to simply my code below: ...
6
votes
1answer
89 views

Multiple Choice Guessing Game

I've built an app for members of an organization I'm in--the app shows the picture of a member with four multiple choice buttons, and the user then tries to guess the member's name. Pretty simple, ...
5
votes
1answer
71 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 ...
4
votes
1answer
54 views

Concatenating a SoundCloud Playlist Update JSON

I am currently working on an implementation of SoundCloud for a 3rd party iOS app, and as there is no SDK anymore I am doing all my calls via Alamofire. This is what SC expects you to send in your ...
10
votes
1answer
83 views

Finger painting code

I have a very simple view that handles touch events and draws accordingly. It's nothing significant, but it does use a bit more CPU than I would like (35%). Again, it is the bare minimum (<90 ...
11
votes
1answer
699 views

Layered Neural Network in Swift

I am designing a very basic layered neural network in Swift as an exercise. I currently got the network evaluating the response for a given stimulus by propagating the stimulus forwards through the ...
4
votes
2answers
84 views

Sprite-Kit/Swift game

I was writing a game in Swift and Sprite Kit and it is very simple. It works perfectly other than the fact that it gets a bit laggy sometimes. I'd like to use this experience as both a learning tool, ...
-1
votes
1answer
31 views

Globally accessible helper class [closed]

I would like to get opinion if I am doing this right. I am creating a helper class that is globally accessible to my whole project. I want it to be easily called like ...
3
votes
1answer
39 views

Save total number of attempts NSDefault

I'm very new to Swift and programming in general. I'm creating a quiz application and am trying to create a function that will save the number of times a user has completed a quiz. It appears to work ...
3
votes
1answer
46 views

Managing a wish list from an API

I have a class that I use to manage a list to/from an API in Swift. Using a clean code approach, I'm wondering if, how, and why I should change it when I have a class that uses it for just one or two ...
2
votes
1answer
86 views

True or false quiz logic

I am creating a true or false quiz game and when the user chooses an answer a tick or cross will appear on the screen telling the user whether they are right or wrong and then automatically bring the ...
3
votes
1answer
141 views

Show a quiz from JSON in iOS

I have to create a quiz of showing questions from a JSON and post back the answers. Here's the structure of JSON: ...
6
votes
1answer
45 views

Create random way from one point to another in map

I've coded a function which uses a map and creates a random way between two points. Startpoint is always 0/0 and the goal is somewhere else everytime on the map. Now I'd like to know if I could ...
6
votes
1answer
79 views

Quiz game logic

I spent a long time searching for ways to create a quiz app and to create a way to sort through non-random questions. The only way I was able to create was to use a series of 3 dictionaries that are ...
6
votes
1answer
184 views

C Socket API Call with Swift

I have a small function in Objective-C which uses the C Socket API to check if the device has an active internet connection: ...
2
votes
1answer
71 views

Decode an alarm keypad message

In my efforts to learn the Swift language, I am trying to mix in a pet project along with my learning of the basic language syntax. In essence, i'm trying to write an iOS keypad application to work ...
4
votes
2answers
150 views

Asynchronous HTTP JSON request

For asynchronous requests, I use Alamofire. I have created one method for requesting async data. ...
1
vote
3answers
54 views

Computed properties vs methods with shape classes

I'd be interested in hearing what folk think are the pros and cons of the following two ways of writing classes like the following Circle, ...
17
votes
1answer
209 views

Ultimate FizzBuzz

Swift's SequenceType is a useful means of generating a sequence of values, and it makes it particularly useful iterate over these values. I don't really have much ...
4
votes
2answers
116 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 ...
6
votes
2answers
56 views

Handling calculator keypresses

I've added decimal (floating point) functionality to my calculator implementation; it's working but I'm having trouble making it more concise and less ugly. I'm trying to use the same method to ...
8
votes
1answer
486 views

First assignment for Stanford iOS8 Course: enhancing a calculator

I recently started learning Swift through Stanford iOS8 Course. The first assignment is to add some features to simple Calculator which was presented during lectures. List of tasks: add button for ...