The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Questions tagged [swift]

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

Filter by
Sorted by
Tagged with
2
votes
1answer
232 views

Wrapping the iOS triple buffering procedure in a generic swift class

In the Metal sample code and best practices guides it is advised to use a triple buffering technique to avoid access conflicts between the cpu and the gpu. The required code to do so requires ...
3
votes
1answer
190 views

Symbolic derivative in Swift

I just wrote my first Swift program! It is a little computer algebra test that computes the nth derivative of the symbolic expression \$x^x\$. I chose this example because I'm keen to see how ARC will ...
2
votes
1answer
2k views

Create a view with a thick inner border that has a gradient

InnerGradientBorderView is a subclass of UIView that has a thick border with a gradient. I have tried to replicate the Zoom ...
2
votes
2answers
311 views

Unit test for a password-change request

I'm studying unit testing in swift and I would like to know if I'm doing the right way. Here I have the model ...
1
vote
0answers
99 views

UIImageView Animation with duration change

I have an array of UIImages that I animating using UIImageView, and creates an effect of wave. the user have plus and minus ...
2
votes
2answers
593 views

Console Based Snake Game

This is a simple program where the goal is to visualize a virtual game to be played by an AI. For the purposes of this post, the playGameManually() function was ...
1
vote
1answer
48 views

Error handling Beacon scanning

I've recently began trying to put more error handling in to my code so I thought I'd post a use-case to check I'm on the right path. I feel like this is going to make my functions much larger and more ...
2
votes
1answer
160 views

HackerRank Caesar Cipher, not using map, filter, reduce, regex

Julius Caesar protected his confidential information by encrypting it in a cipher. Caesar's cipher rotated every letter in a string by a fixed number, K, making it ...
2
votes
1answer
764 views

Parse heterogenous JSON array

I need to parse a JSON generated by iTunes Search API. I'm looking for all apps by a certain developer, and I usually get a response like this (simplified): ...
1
vote
2answers
764 views

iOS tableView with two special rows of headers

Using swift for iOS, here is my cellforRow method ...
1
vote
1answer
71 views

SKAction on SKLabel with array of Strings

I have an SKLabel attached to a parent SKNode and an array of strings: ...
1
vote
3answers
138 views

Navigation controller in Swift

I was looking for a way to write this code shorter and still get the same result. Can this be achieved? ...
1
vote
2answers
102 views

Boolean array, NAND of [SKSpritenodes]

I'm using spritekit, using on touch to detect what the users has tapped, ie., no collisions, etc. I have an array of sprite nodes which in effect is a multi-state boolean switch for now the user ...
3
votes
1answer
205 views

Sorting a list of phone numbers by teleconference provider and location

I'm looking to order an array of phone numbers with a primary sorting criteria of whether the teleconference provider is correct and a secondary criteria of whether the the location of the phone ...
1
vote
1answer
3k views

Extension for grouping array into two dimensional array based on element ([] -> [[]])

I'm new at generics, but I've written an array extension to group an array by array element into a two dimensional array: ...
1
vote
1answer
424 views

Create new UIImage each time or once

I am writing a control that has a toggle on (show/hide password). The UITextfield has a UIImageView in that acts as the toggle. ...
1
vote
0answers
1k views

Upload multiple photos to server

I am uploading an array of photos to the server (using Alamofire): ...
3
votes
0answers
570 views

Applying Gaussian blur to UILabel

Here is the code and it is really slow, like seconds slow to render about 25 labels. ...
11
votes
2answers
2k views

Computing the integer square root of large numbers

The "integer square root" of a non-negative integer \$ n \$ is defined as the largest integer not greater than \$ \sqrt{n} \$: $$ \operatorname{isqrt}(n) = \lfloor \sqrt{n} \rfloor = \max \{ k \in \...
2
votes
1answer
193 views

Toggle case of a string in Swift

What is benefit of using uppercased() / lowercased() over the following approach ? (Other than making it more readable) Any ...
1
vote
0answers
191 views

Singleton lock for a queue

This is a singleton class which can be accessed anywhere including the shouldLock variable. I want to make sure that the variable is thread safe. Basically the <...
1
vote
2answers
846 views

Finding the number of perfect squares in an array

I am posting here for feedback about the code that I wrote to count the number of perfect squares in an array. ...
4
votes
1answer
705 views

Drawing a word, with a box around one letter

I'm working on a draw function which needs to draw the word 'crux' in the center of the current view and then draw a red box around the 'x' character like this: My ...
3
votes
1answer
463 views

Checking whether strings are permutations of each other in Swift

I'm solving this problem on Hacker Earth, just for practice. The exercise is to determine whether two given equal-length strings are permutations of each other. Except for this one test case, which ...
2
votes
1answer
244 views

Handling several types of messages over a web socket connection

I have a UIViewController with a Socket Connection established once viewDidLoad. This web socket is a multi-directional ...
2
votes
1answer
2k views

Filtering input characters for a numeric text field using logical operators

I did my code for "Bronze Challenge: Disallow Alphabetic characters" exercise in "iOS programming" book by Big Nerd Ranch (p.85). When I did the exercise I also changed code of func textField which ...
2
votes
1answer
344 views

Webservice class with parser using generics

I'm currently building a small web stack in swift for use in my iOS apps. It consists of multiple components and I want to make it resource specific; To that end, I have a ...
2
votes
0answers
94 views

Listening to sensor data and logging its output

I am creating a Mac OS X application. This application will connect to a MetaWear sensor over ble, and log the accelerometer and gyro data (I want to store 30 samples for each, per second). Here are ...
1
vote
1answer
58 views

Notifying view controller of changes to any of five types of models

I have a swift 3 project with a code that's look like very generic, but I don't know if I can reduce a method like this one : ...
3
votes
1answer
132 views

Project Euler problem #14 (longest Collatz chain) in Swift

This is my Swift code for finding the starting number, under one million, which produces the longest collatz chain. ...
5
votes
1answer
10k views

Get a specific value from a big JSON response

I have this code to access travel time from the Google directions api JSON result: ...
4
votes
0answers
487 views

Update UI once all API calls are done

I'm learning Swift at the moment but I would like to produce well-organised code. The goal of my little app is to display the weather of my current location. I use : the API of Darksky : https://...
-1
votes
1answer
100 views

Is my code Declarative (RxSwift) ? Please help me to explain why not?

I'm newbie in Swift and Rx programming. Is my below code is declarative ? If not, please rewrite it and explain to help me more understanding about declarative :( (my English is so bad) ...
1
vote
1answer
174 views

Unit testing needs only optional methods of protocol in Swift

I have a protocol which has quite more methods, it looks like: ...
0
votes
1answer
223 views

Find common directory path

I answered the problem of Find common directory path from Rosetta Code. The problem consists of passing '/home/user1/tmp/coverage/test', ...
2
votes
1answer
51 views

Class to classify and compare alphanumeric symbols

I need a class to handle sequences of the following Symbols: 0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ. Digits, lowercase and uppercase symbols will be handled differently. I will ...
1
vote
1answer
227 views

Selection sort algorithm in Swift

I have written selection sort in Swift. Sort([2,4,23,268,9,0]).bySelection() I am looking for ways to further improve this programme using Swift language ...
3
votes
2answers
2k views

Comparing strings, ignoring case, punctuation, and whitespace

I have built a search function that will compare strings regardless of punctuation and whitespace. It is case insensitive. Here is my current function: ...
3
votes
2answers
2k views

Counting neighbor cells of a matrix

I was given this problem to solve inside a Swift playground. I was vaguely told my answer is correct but not good enough. ...
2
votes
2answers
4k views

Enum with associated value as stored property in Swift extension

I have a service which connects to server using socket and stays connected, I used this enum to manage connection state: ...
2
votes
0answers
163 views

Comments on singleton Swift status bar alert

I was trying out some projects like a status bar alert. It made most sense for this status bar to be a singleton: there is only one alert visible at a time. ...
1
vote
0answers
74 views

Runtime function in Swift

I have the following case, I need to delete a specific observer for the firebase database reference, so I made a code that looks something like it looks to the ...
2
votes
1answer
75 views

Algorithm optimisation to get first parent with specific kind of class

I am writing an extension for UIViewController to search all the parents and return a specific parent which is a kind of specific class. here is my try : ...
4
votes
1answer
763 views

Maintainable networking layer architecture

There are so many different solutions and examples on how to build a proper networking layer, but every app has different constraints, and design decisions are made based off trade-offs, leaving me ...
3
votes
1answer
237 views

Implementation of a piece table in Swift

I have implemented a piece table in Swift, based on a Javascript implementation. I don't have much experience with Swift yet, so I'm especially interested if I'm doing things "the Swift way". Any ...
3
votes
1answer
1k views

Basic Caesar Cipher in Swift 3.1

I have been learning Swift for the past day and thought I'd try a basic problem where I can do String manipulation. I am only on pg.100 of the Swift Programming Language on iBooks. Compared to python ...
2
votes
1answer
2k views

Int-Enum to String and vice a versa in Swift

I have a situation in my client-server app where I have to send my network strength to server and also receive other clients' strength from server. So I created enum as: ...
1
vote
0answers
310 views

Handler for a UI to select multiple days of the week for notifications

In the app I am currently working on, there is a part where user can set multiple local notifications for specific weekdays. The array of buttons is represented by a separate class, which utilises ...
1
vote
1answer
98 views

Large switch statement bucketing system

I've finally got a solution for a "weekly streak" bucketing system I've been working on but unfortunately it's resulted in a very large switch statement. I'm running through a handful of dates and ...