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
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 ...
7
votes
2answers
430 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 ...
7
votes
3answers
4k views

Unique random number generation in Swift

In the process of learning Swift, I'm building a lotto numbers generator that generates a random number and appends it into an array, if the number already exists then it should re-generate a random ...
7
votes
1answer
2k 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: ...
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 ...
7
votes
1answer
952 views

Hangman in Swift

I am a Java programmer trying to learn the ways of Swift. I coded a Hangman game in Xcode. I was wondering what I could improve, specifically whether I used delegation correctly and if there is ...
7
votes
2answers
415 views

Postponed Prime Sieve in Swift

Motivated by this question, I looked out for other "infinite prime generators", i.e. functions which produce the list of prime numbers in increasing order and do not have an a-priori upper limit (such ...
7
votes
1answer
8k 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 ...
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/...
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 ...
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 ...
7
votes
1answer
142 views

Swiftly counting rooms in a floor plan

Inspired by recent questions about counting the rooms in a floor plan (1, 2, 3), here is my attempt to solve the problem with a Swift program. The problem (from “Counting Rooms” on CSES) is: You ...
7
votes
1answer
331 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 ...
7
votes
1answer
1k views

Choosing a random flat color

I have a big array of custom flat colors with perhaps 100 lines: ...
7
votes
2answers
181 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
1answer
665 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 ...
7
votes
4answers
1k 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 ...
7
votes
1answer
9k 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 ...
7
votes
1answer
1k views

Adapting layout for various iPhone and iPad screens using constraints and multipliers

My experience with autolayout tells me that it's very difficult to make app look good on whole variety of devices (from iPhone 4s to 6s especially). Size classes are useful with device position and ...
6
votes
1answer
1k 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 ...
6
votes
3answers
11k 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 ...
6
votes
3answers
359 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: ...
6
votes
2answers
282 views

Password generator class

I've written this class to generate a random password and was wondering if there's anything I could improve upon here and whether or not this a safe (most random) method of generating a password. ...
6
votes
1answer
4k 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: ...
6
votes
2answers
240 views

Project Euler solution #2 using Swift 3

I just wanted some review and opinions. Any better implementations or suggestions would be great. Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting ...
6
votes
1answer
7k 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? ...
6
votes
2answers
3k 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 ...
6
votes
1answer
795 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
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 ...
6
votes
1answer
2k 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, ...
6
votes
1answer
118 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 ...
6
votes
1answer
84 views

Downset calculation code

I'm looking to port a Python script I have over to Swift, partly for some performance benefits, and partly to dip my toe into a new language. My program computes what is called the downset of a ...
6
votes
1answer
4k views

UIButton subclass with animated 'shimmer' effect

In earlier versions of iOS the lock screen had a 'slide to unlock' element which I'm referencing as a 'shimmer' effect. The effect I'm looking for is simpler: Button starts with single color (e.g. ...
6
votes
2answers
98 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 ...
6
votes
1answer
4k 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 ...
6
votes
1answer
56 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
551 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. ...
6
votes
1answer
186 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 ...
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
2answers
6k views

Core location background update and upload to server

I want to upload a user's location to a server to send them a location-sensitive alert, so the location needs to be fairly accurate: ...
6
votes
1answer
479 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 ...
6
votes
1answer
545 views

RSS feed parser

I've just started learning Swift. I started with an example of RSS feed parser. I have a wrapper class written in Objective-C which converted the XML response into ...
6
votes
1answer
1k views

Simple Tip Calculator

This is something I put together recently, and I thought I would see if anyone had any recommendations for modification of this short implementation of a tip calculator. The calculator uses a ...
6
votes
1answer
370 views

A* Generic Implementation in Swift

My first Code Review post. I'm up to a generic implementation of the A* search algorithm in Swift (for now, it's a single goal implementation). Here's what's been coded so far: ...
6
votes
1answer
544 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. ...
6
votes
0answers
392 views

Swift class to check ApplePencil reachability

I've implemented a class that lets you check out whether there is an ApplePencil connected to the device or not. ...
5
votes
2answers
318 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, ...
5
votes
2answers
657 views

Asynchronous HTTP JSON request

For asynchronous requests, I use Alamofire. I have created one method for requesting async data. ...
5
votes
2answers
146 views

Splitting an amount of money equally between a group of people

I'm building a clone banking app at the moment, and one of the things I'm trying to do is add Split Transaction (which can then be shared with a set of friends paying a given amount each). Initially, ...
5
votes
1answer
212 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 ...