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
1answer
239 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 ...
10
votes
1answer
4k 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 ...
10
votes
1answer
598 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: VenueService....
6
votes
1answer
477 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
219 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 ...
4
votes
3answers
5k 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
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 ...
7
votes
2answers
426 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
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 ...
2
votes
1answer
127 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
118 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 ...
7
votes
1answer
21k 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 ...
14
votes
2answers
4k 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
1answer
4k 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
4k 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 ...
2
votes
0answers
396 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. ...
15
votes
1answer
6k views

IBDesignable UICheckbox

A more up-to-date version of this control can be found on GitHub. One UI control that has always been mysteriously missing from Xcode's interface builder is some sort of checkbox. ...
7
votes
2answers
181 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
294 views

Error handler for HomeKit app

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 ...
9
votes
1answer
2k 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
186 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
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. ...
24
votes
1answer
11k 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
286 views

Project Euler #6 (Sum square difference) in Swift

...
3
votes
1answer
1k 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 ...
8
votes
0answers
1k 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 closure,...
6
votes
1answer
4k views

Timer UI-updating implementation for educational purposes

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 Stack Overflow question. The idea is that there's some data that is updated ...
6
votes
1answer
543 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
3k 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
2k 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 3-...
7
votes
2answers
1k 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 ...
20
votes
4answers
3k 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
588 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
2k views

Int extension for translating integer to plain English

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

Counting the total value of Card instances given

I am trying to write a function called countHand() that takes in an array of Card instances and counts the total value of the ...
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. ...
8
votes
2answers
2k views

Fraction (rational number) structure with custom operators

First, the struct itself: ...
23
votes
9answers
3k views

Is this FizzBuzz Swift-y?

...
8
votes
2answers
11k views

Is this a correct use of using protocols and delegate pattern in Swift?

I am trying to grasp the concept of delegates and protocols in Swift. So I have implemented my own PlayableMedia protocol with two concrete classes ...
12
votes
1answer
3k views

Swift string multiplication

I like Ruby's string multiplication so I thought I'd see if I could do it in Swift. I came up with these implementations: ...
11
votes
1answer
4k views

Storing global styles and utilizing them throughout view controllers

Assuming an app has many display styles, fonts, colors, etc., and that we never want to hardcode values, I've created an AppVariables object that houses properties ...
6
votes
1answer
545 views

RSS feed parser

I've just started learning Swift. I started with an example of RSS feed parser. I have a wrapper class written in Objective-C which converted the XML response into ...