Swift is a multi-paradigm, compiled programming language developed by Apple for iOS and OS X development.

learn more… | top users | synonyms

0
votes
0answers
22 views

Showing segue after button action

I have an iOS Swift app with 8 buttons that call the same segue, but this is very repetitive. How can I refactor so it uses the same function prepare? ...
7
votes
6answers
1k views

DFT (Discrete Fourier Transform) Algorithm in Swift

I am looking to replicate in Swift what the FFT function does in Matlab. Essentially, it takes an arbitrary length signal (not necessarily a multiple of \$2^n\$) and gives real and complex DFT ...
2
votes
1answer
60 views

Convert ISBN10 to ISBN13

Looking to confirm that I am doing this in the most efficient way. ...
0
votes
0answers
28 views

Mocking protocol with class/static functions in Swift

I am using one of the open-source Objective-C keychain wrappers to store data in iOS keychain. For test cases, I have created protocol as: ...
0
votes
0answers
36 views

Filtering two attributes using Firebase

I have a game data structure in Firebase that looks like this.. I have a view controller in my app that loads up all the games for a specific team. I have the following code which works. ...
4
votes
2answers
131 views

Parsing and converting DMS Coordinates from String to Double

I have some coordinates looking like N47° 15' 36.75",E011° 20' 38.28",+001906.00 and I've created a class to parse and convert them to Double: ...
6
votes
1answer
66 views

Mocking UserDefaults in Swift

In my application, I am using UserDefaults to save some data. I also started writing tests for testing my application code. At one place I stuck where I wanted to ...
5
votes
2answers
92 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 ...
5
votes
0answers
74 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. ...
1
vote
0answers
19 views

XMPP XML Parsing and Tests in Swift

I am implementing chat app using XMPP. Here is my XML Parser function which tells me whether given XML is file transfer offer or not: XMPPIQ+FileTransfer Extension-> ...
0
votes
0answers
26 views

Simple tapping game in SpriteKit

I wrote this as an answer for someone in SO. After writing it I realized it looked pretty good, and was wondering if anyone else thought so as well--or if there were any general improvements to ...
2
votes
0answers
30 views

Posting iOS notifications from sender or from receiver

In Swift, should I be posting notifications to the iOS notification center from the device sending a text message or from the device receiving it? I'm using ...
0
votes
1answer
111 views

iOS Core Data Model with Swifty JSON

I have been using SwiftyJSON to create my models of Object in Swift. But recently, I moved to CoreData for saving the objects locally. I am new to CoreData and want to know the best practices I should ...
3
votes
1answer
79 views

Singleton class with custom initializer

In a Swift project, I have a class should be used as a singleton: ...
1
vote
1answer
43 views

Setting constraints for dynamic views in iOS

I have an app which uses Stack Views to update its UI depending on the number of pigs. For example below, 1 pig and 4 pigs. I set up Stack Views in Storyboard and set isHidden to true based on how ...
2
votes
2answers
67 views

Property value from an asynchronous operation

I have an app which has a session mechanism. When a user creates an account in the app initially, the API returns an access token, the expiry date of that access token and a refresh token which can be ...
-5
votes
1answer
97 views

How can I clean my swift code [closed]

Here is my code . I am not sure is it best practice or not? Please help me to clean my code. I initial all value. Should O put all in optional ?. Is there any ...
1
vote
1answer
61 views

Allow UITextView to resize as the user is typing

I want to be sure that in terms of auto-layout or just following the proper methods of doing the following is acceptable. I am not sure if there will be an constraint issues or efficiency problems ...
1
vote
1answer
138 views

Find substring of a string in Swift 3

I am using this basic extension for a Swift project. It works well, but I want to make sure it is the absolute fastest way to get a substring. ...
0
votes
1answer
39 views

Simple HTTP API requests in an exam paper download app

So basically I am building an app that helps to download some documents via a rest api. Here is the SearchViewController ...
3
votes
1answer
49 views

Simple War game in Swift

I'm new to swift and I want to know if I'm doing something wrong or a harder way. I made a simple war game app. Tames of variables aren't correct, I know, but I was doing it quickly and I didn't worry ...
1
vote
1answer
73 views

Flexible String tokenization in Swift

I want a flexible and fast way to break a string up into strongly typed tokens so that I can do things like the following: ...
3
votes
0answers
22 views

Comments on a 'PullableView'

I created a view called PullView which adds a level of interactivity to UI components. PullViews can be pulled sort of like a ...
1
vote
2answers
99 views

Showing activity indicator (loading image) while processing in background

I have a login screen on my iOS app. When I click login button I want to make sure that user should be displayed a loading image in center of the screen. I found lots of different methods online but ...
4
votes
1answer
94 views

Search a string for barcodes but ignore certain characters

I had to write a string search function that would search for barcodes, and be forgiving of minor formatting differences. For example, the barcode may be entered as ...
3
votes
1answer
52 views

Optimal custom operator with generic type constraint for numerical type

I'm implementing (for an article) two custom infix operators: ¿% - to calculate percent of total %? - to calculate the percent ...
1
vote
1answer
65 views

Configure Table cell in model class

I'm trying to show data in UITablleView after getting it from an HTTP request. I heard that the best and professional way to do it is configure the cell and do the ...
3
votes
1answer
58 views

Transformations an array, combination of between map and reduce

I'm working on a function that reduces pairs of elements if they meet some criteria. For example, given an array: ["1", "2", "a", "b", "3", "4"] I want to ...
0
votes
0answers
87 views
4
votes
2answers
356 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
1answer
56 views
5
votes
1answer
105 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 ...
2
votes
1answer
92 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
34 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
70 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
96 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
60 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
70 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
201 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
114 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
84 views

UIAlertController and input validation

I'm refactoring some "old" Swift code using deprecated UIAlertView and delegates. I have a UIAlertController with an input ...
4
votes
2answers
134 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
284 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
67 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
219 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
31 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
52 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
53 views
1
vote
0answers
33 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
112 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 ...