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
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 ...
29
votes
0answers
888 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
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 ...
7
votes
2answers
2k views

Generic NSMapTable replacement written in Swift

This is my attempt at writing a generic NSMapTable with weak keys and strong values (after your feedback I'll be trying to write Strong-Key/Weak-Value and Weak-Key/...
6
votes
2answers
2k views

Clear function for Stanford iOS 8 Calculator application

I am following the Stanford iOS 8 lectures and I believe I have successfully added the "Clear" functionality to the application, but I don't know if I am doing it properly. Controller ...
3
votes
1answer
1k views

Deleting email using mailcore with imapSession

The following function works fine. However, deleting 1 mail takes about 4 seconds (from start of operation to the firing of the completion handler). Currently, using ...
6
votes
1answer
552 views

Swift API controller

I've just started iOS development and learning Swift. My code below works, but I'm interested to know in ways I can improve it having no experience in iOS Swift prior to this attempt. ...
2
votes
1answer
4k views

Array to Tuple in Swift

I am burdened with the requirement of interacting with a C based library, which has a bunch of constant sized arrays (e.g. char[17]). When trying to assign or read ...
7
votes
2answers
8k 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
87 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 ...
7
votes
1answer
1k views

Choosing a random flat color

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

Validating conditions for enabling sign-up button

On an 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: ...
37
votes
4answers
30k 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 ...
17
votes
2answers
19k 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
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. ...
4
votes
1answer
408 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 of ...
2
votes
2answers
297 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 ...
2
votes
2answers
995 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 ...
3
votes
1answer
242 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
602 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
485 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
224 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
436 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
119 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
397 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
182 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
187 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
289 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
548 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. ...
3
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 ...