Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development.
2
votes
0answers
11 views
didSimulatePhysics to animate a ball, taking 45% of CPU
According to my time profiler this is taking 45% of my cpu usage: have tried to optimize, and someone on stack overflow -- recommended to post here. Time profiler says 99% of the time is spent on the ...
1
vote
0answers
24 views
Expandable tableView cells
What I wanted to achieve is tableView with clickable cells, anytime somebody click a certain cell, another cell with picker, UITextField etc appears below, it's like a dropdown menu.
When browsing ...
1
vote
1answer
22 views
Export class instances to a string (for sharing, backup) and importing them
I have a class (Patient) with many instances.. I need a way to share the instances with other users, so I thought of converting the instance into a string and sharing it, then reconverting it into an ...
0
votes
1answer
13 views
Passing an NSManagedObjectContext
I've been experimenting with how to pass my managed object context throughout my application in Core Data and I came across an approach that I'd like reviewed.
I've been creating a protocol for all ...
-1
votes
0answers
18 views
Does a UIView object with an embedded UIButton and IBAction defy MVC principles? [migrated]
Does a UIView object with an embedded UIButton and IBAction violate MVC principles?
Example:
...
3
votes
1answer
37 views
Queue improvement
I am just learning swift and tried to make a queue class with enqueue and dequeue.
-The node holds the data for each element
-The enqueue adds an element to the "queue"
-The dequeue deletes the ...
3
votes
1answer
46 views
Implementing joinWithSeparator on a Character array
I recently answered a Stack Overflow question about transforming an array of Characters into a String in Swift. Looking at the question and the Swift standard lib, it appears that there is a method <...
3
votes
2answers
123 views
A generic AVL tree with SequenceType, CollectionType and ArrayLiteralConvertible extensions
I'm learning Swift and trying get a good understanding of some of its many features. The following is an AVL tree implementation with extensions that conform to ...
0
votes
0answers
23 views
Saving Core Data records with one-to-many relationship
This is an weightlifting app that allows the user to maintain a log of lifts (LiftEvent) and information about each lift (Lift).
I'd like to know if this is an acceptable way to save a 'record' with ...
0
votes
0answers
81 views
Copy-on-write linked list with value semantics
I'm implementing a SinglyLinkedList struct that uses a private Node class in its implementation. (See this Gist.)
...
0
votes
1answer
89 views
Private Swift Function as Objective-C Selector
I want to use a private function on a Swift class as a Selector, say for adding an observer for a NSNotification. Obviously ...
1
vote
1answer
73 views
Weightlifting calculator
I'm building a simple iOS app using Swift that calculates the One Rep Max weight a user can theoretically lift. User inputs a weight lifted, the number of repetitions and the app uses one of several ...
2
votes
1answer
38 views
Table View Controller for selecting and saving user default preferences in an iOS app
This is the Swift code from one of the view controllers in my app that calculates a one rep maximum weight a person can theoretically lift. This particular view controller presents a list in a ...
1
vote
1answer
58 views
Check if a number is prime
I'm looking for feedback on the following code which checks if a number is prime using Swift 2.
...
1
vote
0answers
26 views
Abstraction of NSNotification that removes the existing observer for a notification when a new observer is added
I ran into a problem in my app where under some conditions, a view controller might be loaded more than once before its deinit (where I was previously removing the observer) is ever called. So the ...
3
votes
1answer
93 views
Recursive flattening of Swift sequences - an overly complicated approach
I recently read and answered Martin R's Recursive flattening of Swift sequences and continued to play around with the code until I arrived at something that was both pretty cool and possibly an ...
2
votes
2answers
171 views
UIButton Subclass - Overriding getters to return placeholder/default values
I'm in the process of converting a custom UIButton from Objective-C to Swift which has custom properties and default values for those properties:
MyButton.h
...
2
votes
3answers
150 views
Calculate the sum of all primes less than 2,000,000 in Swift
This is a Swift program I wrote to calculate the sum of primes below 2 million, but it is tediously slow.
I am curious about what makes it so slow. My theory is that copying the filtered array is ...
4
votes
1answer
64 views
Switch expression function
I made a bunch of functions and an enumeration, that together allow me to write something like a switch expression. It's not as powerful as Swift switch statements, since it's lacking pattern matching ...
3
votes
1answer
51 views
Model for math facts
I've written a model for an app that generates math facts kids have to solve by evaluating the operation and the difficulty you pass to it at initialization.
I don't like how I am repeating the code ...
1
vote
1answer
44 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
69 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
1answer
153 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
100 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
55 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
125 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 ...
2
votes
1answer
81 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
108 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
113 views
Getting JSON data from an HTTP response 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
237 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
101 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
36 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
50 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
21 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
81 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
92 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
48 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
133 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
56 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
19 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
76 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
46 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
66 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
65 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
80 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
115 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
46 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
118 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
56 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
25 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 ...