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
1
vote
0answers
187 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
659 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
687 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
436 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
219 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
329 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
93 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
127 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
9k 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
460 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
93 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
159 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
211 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
210 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
3k 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
154 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
752 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
223 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
283 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
97 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 ...
2
votes
1answer
147 views

Extension vs Class For ViewModel

What the advantages & disadvantages to each of these approaches pertaining to creating file that takes care of the view configuration to reduce a controller's file size. Main Purposes Are: ...
1
vote
0answers
59 views

Weight Lifting App to calculate a One Rep Maximum

I'd like feedback on the main entity in the Core Data model of my "One Rep Max" weightlifting calculator. All feedback is appreciated and in particular, I'd like to know if I've done a decent job of ...
1
vote
2answers
127 views

Switching between queues in cellForIndexPath method

My tableView is scrolling very slowly because there is a fetch request done in every cellForIndexPath method. I have verified ...
2
votes
0answers
60 views

Choosing structure of fields validation module in Swift

I've implemented abstract module for fields validation according to this MVP clean architecture repo. In a nutshell I've created ValidationGateway protocol ...
1
vote
2answers
1k views

Extensive use of exception for database wrapper

My favourite programming language is Java and I usually use JDBC for database operations. I'm using Swift for one of my projects and I should use a database. The problem is SQLite is only available ...
3
votes
1answer
145 views

Swift Attempt To Reduce Massive View Controller

In an effort to reduce the size of a View Controller class I am wondering if this structure is an acceptable, safe way to modify the UI on a Controller Class. The only thing that I see "wrong" with ...
1
vote
1answer
296 views

Grouping models without dictionary

I want to group an array of structs only using arrays into an array of new structs. In this example I want to group the Person structs by ...
2
votes
2answers
1k views

Prime Factorisation in Swift

I made a playground to try find prime factors of any given number, and it works, and I'm happy with the first function, even if not correctly named - I don't know what to name it. My main need for ...
3
votes
2answers
77 views

Uploading photos of various sizes

In my solution I've implemented transaction-like methods of uploading posts media. For example I'm adding new post with photo. I want to have 700x700, 200x200, 70x70, 10x10 px sizes in my storage and ...
3
votes
1answer
2k views

Iterating 2D array in Swift

I have a situation where I needed to convert NSNumber 2D array to Float 2D array, so I did it like this: ...
1
vote
0answers
352 views

VIPER Architecture

I write Swift and architect apps mostly based on VIPER pattern. The thing I always wonder is, is it a proper to store some temporal values in Interactor? Let me ...
4
votes
1answer
8k views

Creating a array of custom objects from JSON, sent using PHP from a MySQL database

I'm using PHP to send data in JSON to create an array of custom objects in Swift. I've been told retrieveData() is bad code because it's in an infinite loop. I'm ...
0
votes
1answer
330 views

Simple networking layer in Swift using Strategy design pattern

Does the following code demonstrate proper use of Strategy design pattern for a simple networking layer in swift 3? Some code smells I'm unsure about: violates Single responsibiility principle. ...
3
votes
1answer
300 views

Fetch nearby chat users using Firebase and nested completion handlers

I have a method that calls three functions that each make a request to Firebase and pass back data in a completion handler. Once the data from 2 of the completion handlers is sent back, I call another ...
4
votes
0answers
81 views

Swift framework that facilitates making atomic changes to several objects at a time

For the purposes of an app I work on I have created a separate framework that abstracts away the mechanism of making atomic changes to the complex object structures. Each class that has to ...
40
votes
0answers
777 views

Swiftly turning wheels – The May 2017 Community Challenge

This is my attempt at the May 2017 Community Challenge in Swift, with a chain consisting of rigid links. I took this as an opportunity to learn SpriteKit, Apple's framework for 2D games. At least ...
1
vote
0answers
756 views

RxSwift iOS Observable FIFO Queue Implementation in Swift 2

I am trying to develop an Observable queue that executes given Observable chains one at a time. The code will be used to encode videos on an iPhone and only one queue will be needed per launch, ...
1
vote
1answer
308 views

Core-data object with relationships conforming protocol in swift

I have a situation where I have to use protocol to be conformed by NSManagedObject which has relationships with other entities. My protocol is like: ...
2
votes
0answers
688 views

REST API wrapper class with Alamofire + Gloss

I have come up with this structure to handle API calls using Alamofire + Gloss. The multipart method I came up with was kind of in a hurry, it works but I think it could be done much better. So this ...
6
votes
2answers
280 views

Password generator class

I've written this class to generate a random password and was wondering if there's anything I could improve upon here and whether or not this a safe (most random) method of generating a password. ...
1
vote
0answers
156 views

Multi-Context CoreData Implementation

I'm using Mulit-Context CoreData for Asynchronous Saving, which follows this architecture: Here is code stack: ...