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
11 views

Unwrapping optional properties from an optional array of objects

I'm currently working with an SDK where methods return an optional array of objects with optional properties. Only the array itself is optional, it will either be nil or always contain non-optionals. ...
2
votes
1answer
41 views

Show and hide views

I have some buttons in my class that show or hide two views (by setting their alpha property to either 0 or 1) when the user taps on them. I have written a function that uses the ...
6
votes
0answers
105 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: ...
3
votes
2answers
82 views

Avoiding misuse of optional unwrapping: LinkedList

Below is my implementation of a generic linked list in swift. Unfortunately, Swift playgrounds won't run until the compiler is totally happy - often, that involves clang making me explicitly unwrap ...
1
vote
0answers
28 views

Showing Or Hiding AdMob Banners - Purchased vs Not-Purchased IAP Banner Non-Consumable

I have the following code that displays a standard AdMob banner depending on whether the user has purchased an ad-free (banner-free) non-consumable In-App Purchase or not (i.e. If purchased, no ...
1
vote
1answer
61 views

iOS MQTT client app base view controller

I've been working on an iOS IOT client app which uses MQTT. After some reading I decided to go with CocoaMQTT. I have only been programming in swift/iOS for about 2 weeks now, so I thought I should ...
-1
votes
0answers
31 views
1
vote
1answer
58 views

Traversing a Binary Search Tree in Swift

I'm implementing the Binary Search Tree data structure in Swift. It looks like this: ...
1
vote
0answers
90 views

Class Level Properties in Objective-C and Swift Classes

I was recently tasked with architecting a user/profile object in Objective-C and wanted the ability to access a static instance from the class level, similar in style to the way Parse manages their ...
2
votes
1answer
104 views

Using conditional binding

I am new to Swift and I am trying to use the optional binding feature in as efficient way as possible but I am a bit confused on how to use it (if I can) in this scenario: ...
6
votes
1answer
137 views

Creating SwiftReachability Class in Swift 2.2

I am novice at creating independent classes for user. I have seen many Reachability library for Swift, but I need to create my own class for that. Here is my code: ...
2
votes
1answer
67 views

Swift solution to Leetcode “Longest Substring Without Repeating Characters”

From LeetCode medium 3. Longest Substring Without Repeating Characters: Given a string, find the length of the longest substring without repeating characters. Examples: Given "abcabcbb", ...
1
vote
0answers
32 views

Workout tracker and performance analyzer app

With this iOS app, the user can create workouts (e.g., Squat, Bench Press, etc) and then track their progress including current weight and number of weights. Performance calculations are also ...
0
votes
1answer
29 views

Singleton manager/service classes with mockable dependencies in swift

In our swift project, there are multiple service classes that encapsulate functions, mostly network-api calls. They implement a protocol, and depend on other service classes, e.g. an authorization ...
0
votes
0answers
18 views

Class property holds data from database

I have a class, it has two properties: var fruitsPackId: Int var fruitsPackContent: Array<Fruit>? Once the class is ...
0
votes
0answers
57 views

Fullscreen overlay NSWindow using constrainFrameRect(_:toScreen:)

A project I'm working on requires a fullscreen overlay NSWindow that must be trusted to stay fullscreen no matter what. Rather than subscribing to ...
4
votes
0answers
79 views

Unit Testing Against Exceptions

I am writing a Swift library. I'm writing unit tests for that library. I am afraid that some of the code that I am testing will possibly throw exceptions. In Swift, we can handle errors, but we can ...
5
votes
1answer
41 views

Vertical-scrolling 2D platform game

I am working on a vertical-scrolling 2D platform game using GameplayKit, SpriteKit and I am writing it in Swift 2.0. Today I ...
1
vote
2answers
109 views

Intersect two ranges in Swift

Can you think of a reason the following extension should not be used in production, or a better way of implementing it: ...
2
votes
0answers
48 views

Design Patterns in Swift: Visitor

I'm solving the following problem using the Visitor design pattern in Swift: When a quote is requested or an appointment is booked we send out an email to the customer, and build an internal ...
0
votes
0answers
16 views

Design Patterns in Swift: Strategy

I'm solving the following problem using the Strategy design pattern in Swift: We order our parts from three different vendors. Each vendor has its own system for verifying and fulfilling parts ...
2
votes
2answers
66 views

Design Patterns in Swift: Mediator

I'm solving the following problem using the Mediator design pattern in Swift: Assume we track the location of all our mobile mechanics. We have noticed that there are times when a mobile ...
2
votes
1answer
36 views

Design Patterns in Swift: Chain of Responsibility

I'm solving the following problem using the Chain Of Responsibility design pattern in Swift: Not all mechanics are created equally. Some mechanics are more experienced and can do more than ...
5
votes
2answers
61 views

Time manipulation for notification reminders

I'm new to programming, Stack Overflow and Code Review. I was encouraged to post this method here based on a question I posted on StackOverflow here. Let me know if you have tips for improving this ...
3
votes
1answer
55 views

Observer design pattern in Swift

The problem: We have a set of mobile mechanics who are assigned specific zip codes. Each zip code has its own hourly rate. We want to increase and decrease these rates when the number of idle ...
2
votes
1answer
62 views

Extending UITableViewCell to preserve UIView background color when selecting the cell

When a UITableViewCell has subviews with background color set, when setSelected(_: animated:) gets called, all the views are ...
3
votes
1answer
102 views

Fixed-length Sequences in Swift 2.2

The following is an implementation of fixed-length sequences that makes very exotic (and hopefully fun) use of Swift 2.2 types. The question is what exactly is the cost of having the type checker ...
0
votes
1answer
43 views

Factory pattern for image or shape marker [closed]

I'm making a photo marker application and need to make a factory pattern for marker. I think it is not very flexible and overall not good. Would you check my code and suggest what could be improved? ...
3
votes
0answers
106 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
4
votes
1answer
48 views

Classification tree in Swift

As an effort to teach myself Swift as well as to get familiar with machine learning algorithms, I've been trying to implement common algorithms, starting with a Random Forest. This is, for the moment ...
0
votes
0answers
22 views

Filter option for PFQueryTableViewController in Swift

I have a PFQueryTableViewController, and have create a separate TableViewController that allows me to select a filter option. When the user selects an option to ...
7
votes
0answers
50 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 ...
3
votes
1answer
74 views

Tracking a geolocation

I have created this ViewController using Swift. Its job is to track geolocation and draw a line on a map and save it to core data object. I just want some advice on ...
0
votes
1answer
62 views

Stanford developing calculator iOS app assignment

I'm currently learning Swift by following the Stanford developing iOS app 2015 lecture series. I have completed assignment 1 but am wondering if there is any improvement can be made to my code. Also, ...
1
vote
1answer
37 views

UICollectionView button target

Within my app i have a UIButton (avatar button which shows a profileVC) within a UICollectionView this button shows up in about ...
2
votes
1answer
45 views

XCTestCase#waitFalseExpectationUntilTimeout implementation

I am working on an iOS project and I'm in charge of testing most parts of it. As I write some tests, I often have the need to wait for an asynchronous method to finish, and then test that something ...
6
votes
1answer
100 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
193 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
43 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
705 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
91 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: ...
9
votes
2answers
236 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
89 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
92 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
87 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
244 views

Tic Tac Toe in Swift

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

Loading images in the background for a table view

I have fetchData method which fills my imagesArray: ...
4
votes
1answer
79 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
36 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 ...
2
votes
1answer
164 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: ...