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

learn more… | top users | synonyms

4
votes
1answer
19 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
0answers
40 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 ...
7
votes
1answer
72 views

Calculator implementation

With some background and experience in PHP & Python, I'm trying to learn Swift by myself (web, videos, Ray Wenderlich books). I've read that a good first project for beginners is to try and write ...
6
votes
1answer
41 views

Checking two text field for match and checking for null

Is this the most efficient way to do this? Any suggestions on some thing I might have missed or can do better? ...
4
votes
1answer
70 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 ...
2
votes
3answers
38 views

Join 5 optional strings with a joiner character

I need to append some query parameters to my API URL. The consumer of my API would pass me this optional structure called as APIParameters, which contain 5 optionals, one array of strings and rest ...
-1
votes
0answers
29 views

Save bunch of data to CoreData

I have a ViewController with a bunch of data and I want to save it to CoreData. I have manager class which add, delete, find etc. that kind of data. My first ...
1
vote
1answer
56 views

Determining the number of days from today

Today I've got a pretty simple snippet to be reviewed. The function is extremely simple, as all it does is retrieve some entities from Core Data and then compares the ...
2
votes
1answer
59 views

Idiomatic way of handling optional values in Swift

I'm new to iOS development and also Swift. I'm working on a project consisting of a menu that leads to my various experimentations with the iOS SDK. I've written the menu titles and ...
0
votes
1answer
104 views

Frontmost window of the current application that passes a predicate check

After resigning active state (going to the background), the mainWindow property of the main window in the app returns false. Nevertheless, I need a to find that ...
7
votes
4answers
132 views

Typed NSUserDefaults

I was looking around for a Swift wrapper around NSUserDefaults and found some very nice projects (see e.g. SwiftyUserDefaults). Unfortunately, it all boils down to ...
5
votes
2answers
62 views

Registering a plist to NSUserDefaults

I've been struggling with registering a plist into NSUserDefaults and I've finally got it working, though I'm not sure that its written properly. I'm hoping someone ...
2
votes
1answer
71 views

Swift extension: Dictionary<String, AnyObject> to JSON string for URL parameter

Here's a quick extension for [String: AnyObject] dictionaries in Swift. The output needs to be in the following format (order and spacing don't matter): ...
4
votes
1answer
53 views

Save File Manager

I made a class to manage saved file in drive with Swift, and I tried to do the best work. Can someone get me a feedback about this class? What can I improve? Is this a good way to save a file? ...
7
votes
3answers
330 views

Swift iOS - Call back functions

I'm working on an iOS app which handles API request based on authentication. Authentication is done through OAuth and every API request is sent along with ...
5
votes
1answer
109 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 ...
4
votes
0answers
45 views

Recursive flattening of Swift sequences

In Flatten to get all child controls of certain type in a UIView, methods were discussed to recursively flatten a tree-like structure in Swift, resulting in an array of all elements. Motivated by ...
3
votes
1answer
72 views
1
vote
1answer
23 views

Push Notifications - save token id into a database using Asynchronous Request

based on this answer I modified my code. Is this the correct approach now? ...
2
votes
0answers
37 views

groupJoin() in Swift

I have created the following function in Swift for this library I am writing, which joins two arrays on a key (extracted using given closures), and then groups them by key in a ...
3
votes
1answer
123 views

Save token id into a database in Swift

I want to save my users tokens id into my database using POST request in Swift (here PHP code here). I am a bit confused about synchronous and asynchronous request. Is this code the right way to do ...
2
votes
1answer
78 views

removeAll(closure) in Swift

From this library I wrote, I have created this function in Swift, but I'm not happy with the implementation. Can anyone suggest a better way to do this? I really don't like changing counters inside ...
3
votes
0answers
75 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 ...
8
votes
0answers
133 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
119 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 ...
6
votes
2answers
122 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 ...
6
votes
2answers
163 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
62 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 ...
3
votes
1answer
77 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. ...
0
votes
2answers
116 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 ...
5
votes
2answers
214 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
52 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
1answer
169 views

Choosing a random flat color

I have a big array of custom flat colors with perhaps 100 lines: ...
3
votes
3answers
64 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: ...
13
votes
3answers
3k 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 ...
11
votes
2answers
1k 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
148 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
231 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
145 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
106 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
55 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
103 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
62 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 ...
6
votes
1answer
342 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
196 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
82 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
67 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
236 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
2k 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
135 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 ...