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

learn more… | top users | synonyms

-4
votes
0answers
13 views

Swift function error [on hold]

I am trying to print this in my fraction classes but why i am getting error like "Argument passed to call that takes no argument" ...
4
votes
0answers
17 views

Tic Tac Toe in Swift

Any feedback encouraged. My checkForWinner function feels cumbersome to me. ...
1
vote
0answers
14 views

How to remove if condition from my tableView:cellForRowAtIndexPath method?

I have "fetchData" method which fills my "imagesArray": ...
4
votes
0answers
29 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: ...
-1
votes
1answer
19 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
votes
0answers
20 views

UItableview indexing and sectioning algorithm [closed]

I was following the guide in here http://www.edumobile.org/ios/indexed-table-views-in-swift/ but author made a minor mistake in the tutorial. Sectioning algorithm doesn't work properly, it should have ...
1
vote
0answers
30 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
153 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 ...
3
votes
1answer
29 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 ...
4
votes
2answers
75 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
95 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
160 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
77 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
147 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 ...
3
votes
0answers
32 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
109 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
99 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. ...
2
votes
0answers
85 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
57 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
65 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
159 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
82 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
48 views

Calculating risk levels

Let's consider following function that return some risk levels enum type: ...
1
vote
0answers
57 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
94 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
91 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
62 views

Check if objects have coordinates

Here's a function: ...
4
votes
0answers
55 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
185 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
175 views

Basic expressive Swift background thread execution

I created a basic background thread class in swift to replace the ugliness of: ...
2
votes
0answers
206 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
362 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
289 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
273 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
2k 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
53 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
120 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
134 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
884 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
112 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
114 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
444 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
63 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 ...
5
votes
1answer
129 views

Project Euler, Challenge #12 in Swift

The sequence of triangle numbers is generated by adding the natural numbers. So the 7th triangle number would be 1 + 2 + 3 + 4 + 5 + 6 + 7 = 28. The first ten terms would be: 1, 3, 6, 10, 15, ...
7
votes
3answers
1k views

Project Euler, Challenge #5 in Swift

The problem: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of ...
4
votes
1answer
168 views

ReactiveCocoa implementation of async function

I would like a review of the RAC implementation for the function setGist() I've posted the code on GitHub for easier reading. Description: You create an instance ...
2
votes
2answers
926 views

Load text file into an array in Swift

I'm drowning in Swift optionals and error handling syntax. I'm just converting a text file into an array of Strings. One would think that this could be a simple two or three liner but by the time I ...
3
votes
1answer
162 views

Set a font for a UITextView if the font is nil or not equal to desired font

Main question I am setting a font for a UITextView that is a subview in a custom view. I only set it if the user didn't specify the font size in the Interface Builder. I have the following working ...
3
votes
1answer
80 views

Switch statement for adding/removing operands to the text part of a label

I have a switch statement with five cases, and four of them are really similar to the others. How could I properly refactor this code to eliminate the duplication of code? ...
4
votes
2answers
680 views

Removing a subview with a subview from a UIView without memory leaks

I made a custom UITextView for vertical Mongolian writing. It is made by subclassing UIView, which has a subview called ...