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

learn more… | top users | synonyms

6
votes
1answer
54 views

iOS delegation design pattern

I am working on a project that has a Model-View-Presenter structure and use the delegation design pattern that has the following structure/implementation. I would love feedback. The ViewController ...
2
votes
2answers
88 views

Music player in Swift

I made a simple mp3 player that plays, pauses and stops a given song, shows the time elapsed, and has a volume control. I read the documentation and can't figure out the difference between the ...
1
vote
2answers
39 views

Anchor Text String Transformation in Swift

I need to convert a string using these rules: Downcase the string Replace spaces, a blacklist of "invalid" chars, and non-ascii letters (like é) with - Replace ...
5
votes
1answer
675 views

Dot product, ported from C to Swift

This is how I posted a method from C to Swift. I tested it well, it seems to work. It's there a way to write this better, following good practices of Swift? The original is in C and the target must be ...
9
votes
1answer
89 views

Portfolio object made of Asset classes and Securities

I am learning Swift and object oriented programming. I am new to design patterns and protocol oriented programming. In my test code I have several related objects: ...
8
votes
2answers
159 views

Swift replacement for C's for-loop

I recently wrote an entry on my blog regarding unit testing using prime numbers as an example. When I wrote the entry, I wrote my code keeping in minding that proposal SE-0007 has been accepted for ...
1
vote
1answer
50 views

Simple Text Prediction

This is a simple implementation of text prediction using a list of keywords and UITextChecker. This is working correctly, but I think I could have implemented ...
6
votes
1answer
73 views

Reading bytes from packet

I have a device I connect to on TCP socket. I send it a message with what I want and it sends back all sorts of useful information: Header: ...
3
votes
1answer
53 views

Using an Edit box in a table views header section to insert the values into the table using swift

Allow me to provide some context. I have a UITableViewCell that contains an EditText and a Button. This cell is then inserted into the ...
5
votes
2answers
130 views

Tic Tac Toe in Swift

Any feedback encouraged. My checkForWinner function feels cumbersome to me. ...
2
votes
1answer
48 views

Loading images in the background for a table view

I have fetchData method which fills my imagesArray: ...
4
votes
1answer
71 views

Swift menu code

I want to know what do you think about the structure of this code. If you think that there is some structural improvement to be made, tell me! Here is a github link: ...
-2
votes
1answer
34 views

improving parser code

In a toy language I wrote (very LISP-like), the most inelegant part is the parsing. The language is organized as one class per programming construct, each class with its own parsing method. If the ...
1
vote
1answer
91 views

Image Scrolling in UITableView with Parse

I'm trying to create an app that is scalable. One of the main features of the app is to view images from a database to a UITableView. Here is my code: ...
3
votes
0answers
216 views

Caching image in memory or on disk

I am caching an image locally..That same image will be used in few screens. Steps for doing this is as follows: Get image from cache If not present in NSCache, get image from Cache directory If not ...
2
votes
1answer
43 views

Ignore nil values and unwrap optionals returning the value as the wrapped type

My primary concern is that this has been written as a global function. I think it would be better if this was a function of the SignalProducer class but I am not ...
6
votes
3answers
111 views

Loading Configurations from plist into singleton

In my iOS application, I've created a singleton class that reads a configuration plist file and provides accessor methods to easily retrieve the values: ...
5
votes
1answer
258 views

Type to byte array conversion in Swift

I need the byte representation of a given type, especially double, float, int8, etc. ...
11
votes
1answer
171 views

Secret Santa with Groups on Swift

I am working on an special version of Secret Santa with internal sub-groups. Typical Secret Santa (SS) requirements: Cannot be assigned to themselves Should be random Every participant should be ...
6
votes
1answer
234 views

UICollectionView image gallery app

I built an app that allows users to add and remove images in a collection view. I want this to be useful online so I save the images into a database and retrieve them every time. I'm looking for ...
8
votes
2answers
162 views

C hack: replace printf to collect output and return complete string by using a line buffer

I have this great C program I'd like to embed into an iOS app. One passes command line arguments to it and the results are printed to stdout via ...
2
votes
0answers
55 views

Am I using ReactiveCocoa the “right” or most “purely functional” way in this Document class?

Introduction I am still learning both swift and ReactiveCocoa, and instead of directly applying it to one of my projects, I have instead worked a few hours on ...
5
votes
1answer
146 views

Weighted Probability Problem in Swift

I was asked a weighted probability question in a technical interview a few months ago that went something like this: Given an input of colors and an integer "weight" value, randomly return a color ...
4
votes
1answer
115 views

Optimize Data Sending/Querying to Parse Swift iOS

I have a swift method that I'm using to update Parse in the backend when the button is tapped. Votes are being updated: The method acts as a voting system, incrementing a label every time it's tapped. ...
4
votes
1answer
157 views

Updating number of votes with a “Like” button

I have a "Like" button in my iOS app that updates the votes every time it's tapped. Just like Facebook, Instagram, ProductHunt, etc. I have a custom cell where that ...
1
vote
1answer
65 views

Mapping multiple values to an array object

I've reached a point in an application where I need to initialize some coordinates to an array and I wound up using nested for-in loops to accomplish the task. Is there is a better way to accomplish ...
5
votes
0answers
77 views

Generating Phone Words in Swift

I've been playing around with some basic algorithms in Swift. Here I am trying to generate phone words, words which can be mapped from phone numbers using the characters under each digit. I was trying ...
2
votes
1answer
425 views

Implementing the Hashable Protocol in Swift with the DJB hash function

A while back I made a custom String struct (see github repo) because of the difficulties in dealing with Mongolian Unicode rendering when using Swift String or ...
5
votes
1answer
217 views

Star Rating in Swift

So I needed a a star rating feature to appear in my app - it doesn't need to be interactive. I have my app connected to a database I've set up in Parse, and I've made a column for OurRatingof type ...
0
votes
2answers
49 views

Calculating risk levels

Let's consider following function that return some risk levels enum type: ...
1
vote
0answers
63 views

Parsing JSON with generics

I get back two dictionaries, I need to parse through them and put in an array two objects. I think I did a very poor job and I have a feeling there is a better way to make the code more compact and ...
1
vote
1answer
188 views

Ordered dictionary in swift 2

Loosely basing myself on this blog post, I implemented an ordered dictionary. In essence, it's a wrapper struct for a list of tuples with some initialisers and some functions (map, filter, toArray, ...
1
vote
0answers
180 views

Custom view for data input (in-app (non-system) keyboard)

I have made a custom keyboard that gets loaded from an .xib file. I decided to go with an in-app only keyboard rather than a system-wide keyboard because the documentation states: Make sure a ...
2
votes
1answer
67 views

Check if objects have coordinates

Here's a function: ...
4
votes
0answers
81 views

Combining RAC signals and updating UI

I'm using Swift 2.1 and ReactiveCocoa 4.0.4 alpha 1. I'm combining multiple signals to enable a button based on if they have valid inputs. The following code works correctly, but I'm wondering if ...
5
votes
2answers
280 views

Counting words from standard input in Swift

I know Swift isn't exactly meant to be used to write your classic stdin to stdout scripts, and that Python, Ruby, Perl, bash, awk, and friends are much better in this area, but I'd still like to see ...
4
votes
1answer
433 views

Basic expressive Swift background thread execution

I created a basic background thread class in swift to replace the ugliness of: ...
4
votes
1answer
417 views

Canonical Implementation for a Concurrent Subclass of NSOperation in Swift 2

I would like to develop a kind of template or canonical implementation for a concurrent subclass of NSOperation in Swift. See here for my previous request which is implemented in Objective-C. In that ...
4
votes
1answer
632 views

Checking network status

I have this slightly popular Swift library called IJReachability up on Github. It checks the network connection status. Due to my office workload I've been very busy in the past few months so I ...
4
votes
1answer
439 views

Greyscale converter performance in Swift

I have a single class which converts an image's colors into greyscale (except one given color, which will be left as it was before): ...
3
votes
0answers
522 views

Multiple View Controllers in a Single Window (Swift on OS X)

As an exercise I want to have a single window application (in Swift on Mac OS X) with 4 views, each controlled by an independent view controller and have their own XIB file. I have working code, but I ...
3
votes
1answer
4k views

Coredata delete all data in an entity

I have this code that I am using to delete all records from an entity. The question is can it be done better or is already the best? ...
5
votes
0answers
56 views

Moves box in direction of touch, and has wraparound when reaching edge of screen

Part of me thinks that it would be simpler to ditch Apple's move API and just updated position with a timer. I know that's what I did with a JS canvas snake game I built a while ago. But I'm also ...
3
votes
0answers
170 views

“Extending” the Swift 2 ErrorType protocol

I am building a simple REST client in Swift 2. The methods the client offers can return errors. Every method returns the same errors (network problem, unauthorized, etc...). But each method can also ...
1
vote
0answers
162 views

Adding a constraint to a PFQuery on a PFRelation with objects that have already been gotten

For some background, I am learning from the following Stack Overflow question that I asked regarding creating the this code. I was playing around with different combinations of ...
7
votes
2answers
2k views

Background execution in iOS

The following class BackgroundExecutable is to be used to take a function f and return a function ...
5
votes
2answers
135 views

FizzBuzz in Swift 2

I saw this question: Is this FizzBuzz Swift-y? and I couldn't resist the temptation to attempt a Swift2 implementation: ...
1
vote
1answer
138 views

Retrieving creation date from Parse.com data

I got to show the createdAt date in a message timeline, I tried to make a separate array only for dates, but don't know if it is the right path to follow. It seems ...
3
votes
1answer
506 views

Building Weather Forecast from JSON with optionals

I am looking for the best way of parsing JSON in Swift 2.0. I have this JSON ...
2
votes
2answers
68 views

Project Euler, Challenge #17 in Swift

Number letter counts, Problem 17: If the numbers 1 to 5 are written out in words: one, two, three, four, five, then there are 3 + 3 + 5 + 4 + 4 = 19 letters used in total. If all the numbers ...