Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development.
0
votes
0answers
11 views
Touches ended function not executing [on hold]
There seems to be a problem with my touches ended function. My touches began function works perfectly fine, although when i release my touch nothing happens.
Here is my touches began function which ...
0
votes
0answers
8 views
Touches ended not executing [on hold]
Anyone know why my touches ended code is not executing. My touches began function is working fine, although when i release my finger from the touch nothing happens any help?
`override func ...
0
votes
0answers
66 views
2
votes
1answer
56 views
Basic calculator in Swift 3
I just started learning the basics to Swift 3 about 2 days ago. Since then, I've decided to make a simple calculator that can only do one operation at a time.
I was wondering how efficient this was ...
0
votes
0answers
26 views
Sqlite.swift — Selecting all rows and returning them in an array of tuples
Link to SQLite wrapper
...
3
votes
1answer
36 views
Extending CGPoint to conform to Hashable
For Advent of Code Day 1, I found myself needing to use a tuple as a key in a dictionary. Seeing that I can't extend tuples in Swift, I decided to extend CGPoint ...
1
vote
1answer
44 views
Listening to IOKit events with Swift 3
This is my first program in Swift/Xcode. The full source code and xcode project is available in GitHub.
The part I would like reviewed is IOKeyEventMonitor.swift.
...
1
vote
0answers
29 views
Supporting different orientation in viewcontrollers
will you please give your thoughts (code review) on these two way of solving orientation.
About the app:
We have a universal App. The main purpose of the app is to watch the videos. The app has four ...
2
votes
1answer
55 views
Splitting an array into stride by 2
i've written a basic function to split an array into stride by 2:
...
2
votes
0answers
35 views
Generic wrapper for Alamofire Request's function jsonResponse wrapper
I am trying to wrap a responseJSON function of a Request class of Alamofire because when I send an API request I get a response ...
1
vote
1answer
56 views
Checking for required text fields for login
I wrote this script and it's working quite well however I think there's too much if else statements on it. How could I change them for a switch statement?
...
1
vote
2answers
60 views
Checking an authentication decision in a JSON response
I've been working on this login screen logic.
It checks for the parameters in the JSON response to decide which action to follow. It works but it's kinda ugly and verbose. Any suggestions to ...
2
votes
2answers
91 views
Swift 3 Generic fetch request extension
I implemented an extension for the NSManagedObjectContext that takes any CoreData class as a parameter and performs a fetch request on it.
I am new to CoreData ...
3
votes
0answers
107 views
Adding swipe support to multiple classes
I have implemented swipe functionality using UIPanGestureRecognizer in a project.
What I have done is added PanGesture to ...
1
vote
1answer
60 views
UIAlertController and input validation
I'm refactoring some "old" Swift code using deprecated UIAlertView and delegates.
I have a UIAlertController with an input ...
3
votes
1answer
58 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 ...
12
votes
1answer
280 views
Cat fight (with rockets)
My code is attempting to implement FP in an efficient / readable manner into some of my video games. I realize this may be a bit subjective, but I feel there is enough merit / objectivity to be of ...
2
votes
1answer
54 views
Categorized Photo Albums
I was told the function "hompage" was too clunky to conveniently make a tableview. The cells will have the information in "PHOTO ALBUM ICONS" and "BUTTON ON TOP OF PHOTO ALBUM ICONS".
...
8
votes
1answer
205 views
Quickselect algorithm in Swift
I recently answered a question
on Stack Overflow about finding the k-largest element in an array, and
present my implementation of the Quickselect algorithm in Swift for review.
This is essentially ...
1
vote
1answer
29 views
Settings the height of rows for multiple screens within a TableViewController
Is there a better way to write this? This is a class that displays a preferences menu. We do this when the user first installs the app during a walk-through where we only show them some of the ...
2
votes
0answers
39 views
Converting [UInt32] -> [UInt8] -> [[UInt8]]
I am trying to speed up my current implementation of a function that converts [UInt32] to a [UInt8] which in turn is split up ...
2
votes
1answer
35 views
1
vote
0answers
30 views
Formatting data in a UIViewController in a weight-training app
I'm writing a weight training app that calculates a one rep maximum and it has several options including recording your lifts in pounds or kilograms. I'm trying my best to follow the MVC pattern but I'...
2
votes
0answers
62 views
Implementation of a like button in iOS for Instagram like app in Swift
I have just completed an implementation a like button for an Instagram-like app, but now that I am looking at it I feel that there is something off. Maybe it is my formatting or maybe I am not quite ...
3
votes
1answer
175 views
Displaying JSON data from a server in a UICollectionView
This code pulls JSON from a server and delivers some data like imageURL, titleString and ...
0
votes
1answer
71 views
Extract regex matches with non matching parts
I want to check a string by using multiple search patterns and split the string at every occurrence. I'm using RegEx and it works fine. But I'm worrying about efficiency and performance.
...
0
votes
1answer
74 views
Accessing a UIView's parent UIViewController using the UIResponder chain
I recently found a static C function on Stack Overflow which returns a UIViewController reference from a containing subview using the responder chain:
...
3
votes
1answer
165 views
Swift FloatingPoint rounded to places
I'm playing a bit with extensions for default protocols in Swift 3.0.
I would like to implement rounded(toPlaces places: Int) -> Self for ...
3
votes
1answer
53 views
Creating an area graph in iOS
I am trying to create an area graph from the upper and lower limit values.
First I created two line graph from those points as:
Sample data points are:
...
0
votes
0answers
44 views
View controllers and delegation for a weightlifting app in Swift
I've got several UIViewControllers that are trying to do too much so I'm trying to learn how to clean them up so that they only have code that does UI things (...
0
votes
1answer
44 views
Calling a method only once in an updateScore function in SpriteKit
This works fine, but obviously it's messy and I'm thinking there has to be a better way to do this. Having to constantly remember to flip the bool back is a pain, is there anything else I can do here? ...
1
vote
0answers
110 views
A custom UIView with gradient fill, border, and variable corner radii
Here is a swift port of UIView subclass that I use often in my apps. It allows me to easily set gradients in place of the backgroundColor property, and also makes it very easy to create views that ...
2
votes
1answer
205 views
Signing a String using an identity and trust from a PKCS #12 Bundle
One of the requirements of a third-party SDK I am integrating with is to sign an identifier string with the identity from a p12 certificate. This code loads a p12 certificate from the application's ...
2
votes
1answer
493 views
AES-128 Encryption/Decryption of NSData
I recently found an Objective-C extension on NSData that encodes and decodes data with AES-128. I made an attempt to port this code to Swift 2.2:
NSData+AES.swift
...
1
vote
0answers
70 views
Calculating the tip and tax portions for a refund amount
refundableSale is a PMSale object with properties refundableTip, ...
3
votes
1answer
67 views
Chop off trailing newline for Swift's NSAttributedString
I've made this extension but I'm touchy around NSAttributedStrings, keenly aware that Swift refuses to use the traditional notion of integer lengths on Unicode <...
1
vote
1answer
65 views
LeetCode Counting Bits in Swift
I solve this problem in Swift. I am looking for a code review, thanks!
Given a non negative integer number num. For every numbers i in the
range 0 ≤ i ≤ num calculate the number of 1's in their ...
3
votes
1answer
120 views
Efficient way in Swift to trim an array
Let's say I have a struct…
struct Person {
let isMale: Bool
let name: String
}
and an array of Person structs. I want ...
0
votes
0answers
58 views
1
vote
0answers
58 views
Spawning nodes with random time interval in SpriteKit
I want to spawn objects with random time interval (from 1 to 3 seconds).
I've wrote this function:
...
1
vote
1answer
137 views
Proper cellForRowAtIndexPath cell return in Swift
So I have started creating a UITableView with multiple prototype cells. I currently have the below code setup, which works fine
...
3
votes
1answer
77 views
Safe init using failable guarded initializer
I am wondering if that is a safe and proper init, with one failable init guarded and an init.
Are the force-unwrap correct in the self.init as I know they are ...
3
votes
2answers
102 views
Registering Pokémon weaknesses
I recently answered a question that had me wondering if I could simplify this below code without creating an extra function:
...
2
votes
0answers
46 views
Adding or editing a child
I have a class which will add or edit a child. So whenever I click on "save," I need to check the child image. If it's an image, then I need to upload to the image server. Once that's done only, I ...
4
votes
2answers
129 views
Big Nerd Ranch Bronze Challenge: Disallow Alphabetic Characters
I just completed BNR's bronze challenge for disallowing alphabetic characters, and would love some feedback on what I did right and wrong, and how I can improve my code for reusability and ...
-1
votes
1answer
54 views
Swift inheritance versus composition
Say I'm using Parse Server and utilising the PFObject class from the iOS SDK. Say I want to have a Chat class.
To use inheritance code (design 1):
...
2
votes
0answers
138 views
Hackerrank Simple Text Editor in Swift
I solve this problem in Swift. However, some cases I got terminated due to timeout because the solution isn't efficient enough. I did check the solutions and they are correct. Any tips on making it ...
8
votes
0answers
108 views
Water flowing swiftly over farmland – The August 2016 Community Challenge
This is my attempt to solve the August 2016 Community Challenge in Swift. I tried to implement the algorithm
described by @200_success:
Each Cell keeps track ...
3
votes
1answer
251 views
Swift HackerRank Balanced Brackets
I solved this stack problem in Swift. Looking for any feedback on my code:
...
0
votes
0answers
119 views
Swift Hackerrank Maximum Element in a Stack
I solve this problem in Swift. I'm not sure if using an array was the right way to approach it since the problem was on stacks. Any feedback on my code is appreciated:
You have an empty sequence, ...