Skip to main content
8 votes

Check for iOS version

If you need to check if a certain method exists you can also check if the object supports it via respondsToSelector: like this: ...
iosdude's user avatar
  • 266
8 votes

"What To Do" App

The instance variables var userText : String = " " var randomNumber : Int = 0 are not needed: userText is only used within <...
Martin R's user avatar
  • 23.3k
8 votes
Accepted

Showing a welcome screen once per day

There is some code duplication for the cases “greeting date has never been set” and “last greeting was yesterday or earlier.” This can be avoided if you use the nil-coalescing operator ...
Martin R's user avatar
  • 23.3k
8 votes
Accepted

Changing the color of some pixels in an image in Swift

There are two issues. The process of converting to and from UIColor objects is very expensive. The process of calling contains ...
Rob's user avatar
  • 2,552
6 votes

Up/down arrow key commands

Create an array that contains result values for upArrow, and another array for values of buttonTag for downArrow. Arrays are zero-indexed, so subtract 1 from your buttonTag value before using it as an ...
Duncan C's user avatar
  • 181
6 votes
Accepted

Ring Timer Animation with Chasing Tail using CoreAnimation

There is one problem with your approach: Additional sublayers are added in draw() and in animateTimerReset() and never removed. ...
Martin R's user avatar
  • 23.3k
6 votes
Accepted

Caesar Cipher in Swift (iOS-app)

My main point of criticism is that the encryption logic is in the view, actually in two views: the ContentView contains the code to shift one index forward or ...
Martin R's user avatar
  • 23.3k
5 votes
Accepted

Stanford developing calculator iOS app assignment

I have never seen the Stanford class or this example before, so I might be mentioning stuff that hasn't been covered yet in the class... Inappropriate use of IBActions: Much like ...
Daniel T.'s user avatar
  • 821
5 votes
Accepted

Singleton class with custom initializer

Assuming the dataToTransfer is always the same for a specific device, you can create this data in init() ...
shallowThought's user avatar
5 votes
Accepted

Splitting a long string based on its graphical presentation

General remarks Here are some general remarks that could make your code look a little cleaner : Avoid using ; at the end of an instruction unless you have to put ...
ielyamani's user avatar
  • 879
5 votes

100DaysofSwiftUI - Project 1 - Challenge 1: Convert temperature units: Celsius, Fahrenheit and Kelvin

The conversion function convertedDegreeC2F() handles only four of the nine possible conversions between the three units. In particular, the conversion between ...
Martin R's user avatar
  • 23.3k
5 votes
Accepted

Initializing more than one instance object at a time in init method

A couple of thoughts: You are conceiving the band as being something derived from the frequency. While this may be technically correct, from a user perspective, you generally choose a band and then ...
Rob's user avatar
  • 2,552
5 votes

What can I learn from this coding test?

I'm assuming that the code works and fulfills all the usability requirements that you got. Also assuming that this was a home assignment with "unlimited" time where you could code at your ...
user985366's user avatar
  • 1,725
5 votes
Accepted

Sum of natural numbers below threshold

Improving on your approach Split up your tests So they pass/fail independently: ...
Alexander's user avatar
  • 494
4 votes
Accepted

Tracking a geolocation

You already know exactly what your viewDidLoad method should look like... you just didn't write it how you know it should look. It should look like this: ...
nhgrif's user avatar
  • 25.3k
4 votes
Accepted

Creating SwiftReachability Class in Swift 2.2

Improvements of your code Let's start with your isConnectedToNetwork() method. ...
Martin R's user avatar
  • 23.3k
4 votes
Accepted

Show and hide views

First, I would consider making a reusable method on UIView to encapsulate the alpha toggle: ...
Daniel T.'s user avatar
  • 821
4 votes
Accepted

Finding consecutive days in an array of dates

Never use 86,400 seconds as the duration of a day. "Most" days have 24 hours, but in regions with daylight saving time, a day can have 23 or 25 hours (when the clock is adjusted one hour forward or ...
Martin R's user avatar
  • 23.3k
4 votes
Accepted

Interview Coding Challeng for iOS Part 1 - the Static Objective-C Library

For having never done Objective-C before, this looks pretty good! Here are some things I would do differently. Library Name What is PCI7? For an acronym used in every class in your example, it would ...
user1118321's user avatar
  • 11.7k
4 votes
Accepted

iOS app that signs people up for a street-ball league in their neighborhood

The first thing that I noticed is that you have three view controller classes (MensVC, WomensVC, ...
Martin R's user avatar
  • 23.3k
4 votes
Accepted

Multilingual app without localizing

I did something like this. You can also just use a Strings file. What I did was create a spreadsheet in the Google Drive with all the translations (one column for the identifier BUTTON_TITLE_OK and ...
Joris Weimar's user avatar
4 votes
Accepted

iOS Swift 3 app that requests data from the Stack Exchange API

Property accessors Defining accessor methods for stored properties such as ...
Martin R's user avatar
  • 23.3k
4 votes

Form for OTP entry with six single-character text fields

Your solution to this particular problem is fine in its own way. However when it comes to scaling, it will become quite messy. Since I don't see any scope of improvement/tweaking in your approach, I ...
badhanganesh's user avatar
4 votes

Showing a welcome screen once per day

You could rearrange the conditions this way : ...
ielyamani's user avatar
  • 879
4 votes
Accepted

Create UIView programmatically in Swift

You can move setting properties to lazy var declarations eg. ...
Kamajabu's user avatar
  • 211
4 votes

Sum of natural numbers below threshold

Obligatory Math Solution One of the most useful principles of enumeration in discrete probability and combinatorial theory is the celebrated principle of inclusion–exclusion. When skillfully applied, ...
qwr's user avatar
  • 1,055
4 votes

Show a list of downloads

I am going break this into three parts: Your question about the observer. Some big picture questions about the broader design. And a ton of tactical observations regarding the code in the question. ...
Rob's user avatar
  • 2,552
3 votes
Accepted

Simple War game in Swift

Welcome to Swift! Everything looks like it's working correctly so I'm adding some thoughts that will apply as you continue working and as the code gets more complex... You're not doing anything in ...
MathewS's user avatar
  • 653
3 votes
Accepted

Model for math facts

Disclaimer, I'm a beginner level Swift programmer, so take my feedback with a grain portion of salt. First off, a minor improvement for your newQuestion function, ...
overactor's user avatar
  • 654
3 votes

Core location background update and upload to server

LocationManager Singleton It is not necessary to use dispatch_once to make LocationService a Singleton. This pattern can be achieved by doing the following: ...
Ryan H.'s user avatar
  • 246

Only top scored, non community-wiki answers of a minimum length are eligible