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

learn more… | top users | synonyms

-1
votes
1answer
51 views

Count the number of element in arrays inside root array

I have an array of Room objects. Each Room contains an array of Student objects. So I want ...
-1
votes
0answers
25 views

Dying in Flappy Bird Type Game in Swift [closed]

Im trying to make a flappy bird type game in swift. The game runs fine now but there is no way for the the game to end. Unlike the normal flappy bird game i want the game to end when the when the bird ...
5
votes
1answer
70 views

Equivalent of C-style “Static Local Variable” in Swift

I'm porting some Obj-C code to Swift, and I've written the following code to allow me to deal with "static local variables" which do not exist in Swift. A static local variable has these ...
1
vote
1answer
42 views

Preparing a walkthrough: Freeze effect :s

I have a method that load my walkthrough view. I have my view controller composed of a scroll view. And others views controllers used only for the walkthrough (maybe I should used xib uiview instead ...
6
votes
2answers
109 views

Choosing a random flat color

I have a big array of custom flat colors with perhaps 100 lines: ...
2
votes
3answers
45 views

Computed property or function

On a authentication view, there are some inputs, like password, email , etc .. and a sign up button which is enabled only if theses inputs are not empty. So what I have is this function : ...
7
votes
2answers
367 views

Swift 1.2 Singleton Implementation

I am pretty new to Swift, as a solo developer I was wondering if somebody could pass comments on the singleton implementation below. The code does work, but being new to Swift and knowing that there ...
8
votes
2answers
300 views

Getting WiFi SSID on iOS in Swift

I've seen a lot of Objective-C implementations but I'd like to do it in Swift. I did it like this and it seems to work just fine. Does anyone have comments and/or improvements to make? ...
5
votes
1answer
132 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. ...
-1
votes
1answer
144 views

Simplify expression in Swift playground [closed]

In Swift playground I would try to plot the sum of two sinusoids; all fine if I plot a single sinusoid but my coded expression seems too complex (..even for my MBP 16Gb 2,3 GHz Intel Core i7), so ...
5
votes
2answers
130 views

Not sure how to avoid duplicating code here [closed]

I have this bit of Swift code, which works great and does exactly what I want it to do: ...
4
votes
1answer
86 views

Project Euler #16 in Swift - Power digit sum

I just finished Project Euler #16 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. 2^15 = 32768 and the sum ...
1
vote
2answers
52 views

Project Euler #14 in Swift - Longest Collatz sequence

I just finished Project Euler #14 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. The following iterative ...
1
vote
2answers
68 views

Project Euler #13 in Swift - Large sum

I just finished Project Euler #13 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. Work out the first ten ...
2
votes
1answer
54 views

Project Euler #12 in Swift - Highly divisible triangular number

I just finished Project Euler #12 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. The sequence of triangle ...
4
votes
1answer
97 views

Beginner stopwatch app

I'm learning Swift and would appreciate any code review suggestions (the more nit-picky, the better). In particular, I'm wondering if there's a more efficient way to format the time in the ...
8
votes
1answer
145 views

Networking in iOS Swift

This piece of code is working - It gives me a lot of JSON back, which I have yet to parse, but I'd like to show my code here first to get tips on how to improve what I already have: ...
5
votes
1answer
78 views

Project Euler #10 in Swift - Summation of primes

I just finished Project Euler #10 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. I hope I learned some from ...
2
votes
1answer
50 views

Project Euler #9 in Swift - Special Pythagorean triplet

I just finished Project Euler #9 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. A Pythagorean triplet is a ...
2
votes
3answers
137 views

Project Euler #8 - Largest product in a series

I just finished Project Euler #8 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. The four adjacent digits in ...
5
votes
1answer
666 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 ...
6
votes
2answers
131 views

Project Euler #7 - 10001st prime

I just finished Project Euler #7 in Swift, and since there is not any version yet on Code Review, I would like to have some comments on what I did to try to improve it. By listing the first six ...
5
votes
1answer
197 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 ...
2
votes
1answer
76 views

Finding matching Node instances in an array - running slow

I have encountered a performance issue in Swift. I compared the same method between C# and Swift: Swift is much slower than C#. Here is the code I'm working with. Could some one help me to speed it ...
6
votes
1answer
98 views

Performance of A* route

I'm new to the Swift language. I have a C# version of a simple A* route which is very fast. But I rewrote it with Swift, and the performance is very bad (3,4 seconds for a very simple road). Could ...
3
votes
1answer
1k views

Pure Swift solution for socket programming

I have spend quite some time now to find out how exactly to do socket programming in Swift (Xcode 6.1). There are a few examples out there, but most of them no longer work for the latest release of ...
13
votes
1answer
278 views

Let's play some Swift Poker

Before you can do any sort of card game, you must first write some code to define your deck of cards. One thing I've noticed in looking at some of Apple's Swift interfaces is that they very much so ...
2
votes
0answers
94 views

Usage of MVVM in iOS [closed]

I'm an iOS developer and I'm guilty of having Massive View Controllers in my projects so I've been searching for a better way to structure my projects and came across the MVVM (Model-View-ViewModel) ...
2
votes
1answer
366 views

Subclass SKSpriteNode

I decided to subclass SKSpriteNode for a game test in Swift today and soon realised that it was not as simple as my Objective-C background suggested. After a little ...
2
votes
2answers
487 views

Swift complexities with Dictionary

I have been trying to learn the various aspects of the languages I know so far to do the Daily Challenges in reddit (/r/DailyProgrammer). The one which I am working on just now asks for an ...
1
vote
0answers
145 views

Filling a cumulative array in Swift

I have a "cumulative" lookup array for a custom collection view layout. The idea is that I have an array of rectangles, each with an index. The index is not unique, and is monotonically increasing. ...
14
votes
1answer
744 views

IBDesignable UICheckbox

One UI control that has always been mysteriously missing from Xcode's interface builder is some sort of checkbox. UISwitch is available, but this isn't always ...
7
votes
2answers
143 views

Defining a simple function-calling operator

I have been writing Swift code for a while and have read a lot of tutorials about how functional paradigms can be applied to Swift. I defined a simple operator: ...
7
votes
2answers
147 views

Swift error handler for HomeKit

I have this universal error handler for my HomeKit app (currently in development). It grew out of wanting a single place to write error messages, show alerts, etc. I wanted a short, simple way to call ...
10
votes
1answer
1k views

Piano app in Swift

I'm making my first app in Swift: a Piano app. I'd like to get your feedback especially about how I can make codes shorter. I maybe have to use arrays and loops and something, and searched by myself ...
6
votes
1answer
129 views

Slowdown when swapping between views

I am working on a project called neoCode that takes a users input URL and turns it into HTML or Machine Code. I am so close to pushing this to TestFlight for beta testing but I have a pretty bad ...
5
votes
1answer
466 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. ...
15
votes
1answer
5k views

Rewrite code from Objective-C to conform with Swift power tools and concise style

I started a project with Objective-C and rewrote it with Swift. The project contains two UITableViewControllers: MasterViewController and DetailViewController. ...
4
votes
1answer
155 views
3
votes
1answer
356 views

Images viewer from URLs with download progress

I've created an imageViewer that will be initialized with a String array, and will download and show the images as needed. Alongside a review, could you give me a ...
4
votes
0answers
235 views

Asynchronous Array.map

I put together an asynchronous map function for Swift's Array using Grand Central Dispatch. It's called with a transform ...
6
votes
1answer
1k views

Updating the UI with a timer - code intended to help teach

I thought it would be helpful to put together an example of what I'm talking about in the second part of my answer to this stackoverflow question. The idea is that there's some data that is updated ...
6
votes
1answer
151 views

Project Euler #5 (Smallest multiple) in Swift

I found this one a little bit easier than the previous problems, but I was already familiar with the GCD/LCM formulas. ...
2
votes
1answer
483 views

UISegmentedControl with view-animation

I have create a UISegmentedControl and a view under it. The view under contains all a view for each segment. I am doing an animation when the segment is changing. ...
10
votes
2answers
799 views

Project Euler #4 (largest palindrome product) in Swift

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two ...
7
votes
2answers
262 views

Project Euler #3 (Largest prime factor) in Swift

As mentioned in Project Euler #2 in Swift, I intend to work my way through Project Euler using Swift to make sure there aren't any tricks I'm missing. This is the problem statement for #3: The ...
12
votes
4answers
1k views

Project Euler #2 (Even Fibonacci numbers) in Swift

I figured working through Project Euler problems in Swift would be a good way to learn any tips or tricks. For example, tuples are something I'm not used to using, but they proved useful here. Using ...
5
votes
1answer
93 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 ...
15
votes
4answers
158 views

Int extension for translating integer to plain English

This code was inspired by this question: Number to Words ...
5
votes
1answer
378 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: ...