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

learn more… | top users | synonyms

1
vote
1answer
41 views

For Loop with Index to Functional

Trying to simply my code below: ...
5
votes
1answer
40 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
49 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
41 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
70 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 ...
9
votes
1answer
577 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
1answer
49 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
28 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
33 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
44 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
74 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
116 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
41 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
66 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
99 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
60 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
98 views

Asynchronous HTTP JSON request

For asynchronous requests, I use Alamofire. I have created one method for requesting async data. ...
2
votes
3answers
48 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, ...
15
votes
1answer
176 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
99 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
52 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
223 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
93 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
66 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
101 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
76 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 ...
2
votes
1answer
72 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
79 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
127 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
184 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
141 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
451 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
92 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? ...
8
votes
3answers
2k 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
130 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
1answer
111 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
90 views
1
vote
1answer
42 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
43 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
411 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
182 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
171 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 ...
9
votes
0answers
184 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
168 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
203 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
298 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
95 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
139 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
235 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 ...
6
votes
2answers
686 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 ...