Questions tagged [swift]

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

98 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
40
votes
0answers
781 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 ...
29
votes
0answers
859 views

Making a generic NSMapTable replacement written in Swift thread-safe

This is a follow-up to this question. While discussing some details about the code I posted there, I came upon a problem with thread-safety. After searching and trying different things, I reached a ...
14
votes
0answers
227 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 ...
9
votes
0answers
896 views

Interview coding challenge for iOS Part 2 - the application in Objective-C and Swift

I recently interviewed with a company that needed a C/C++ programmer to work on the iOS side of the products. The job description indicated they needed someone with 4 years of Objective-C and iOS ...
8
votes
0answers
1k views

Asynchronous Array.map

I put together an asynchronous map function for Swift's Array using Grand Central Dispatch. It's called with a transform closure,...
6
votes
0answers
380 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. ...
5
votes
1answer
572 views

Generating Phone Words in Swift

I've been playing around with some basic algorithms in Swift. Here I am trying to generate phone words, words which can be mapped from phone numbers using the characters under each digit. I was trying ...
5
votes
0answers
76 views

Moves box in direction of touch, and has wraparound when reaching edge of screen

Part of me thinks that it would be simpler to ditch Apple's move API and just updated position with a timer. I know that's what I did with a JS canvas snake game I built a while ago. But I'm also ...
5
votes
0answers
2k views

Reducing complexity in NSView event handling code in Swift

My Cocoa event code always tends to descend into madness, I need to advice on how to reduce complexity. I've spend a few hours putting this example together. CanvasView is a layer hosting subclass of ...
5
votes
1answer
2k views

Road to MVC: the case of Settings Table View Controller

Now that I know that MVC can help do better code, I want to make my SettingsTableViewController class conform to it. ...
4
votes
0answers
4k views

Page and center UICollectionView like App Store

I need a collection view to page through cells and center it like the App Store, where a portion of the previous and next cells look like this: The native ...
4
votes
0answers
462 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://...
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 ...
4
votes
1answer
290 views

Notify user of credential failure and make another attempt

The below code works because of the do operator on line 24. Is there a more functional way to get the test to pass, or would you consider this an appropriate use of ...
4
votes
1answer
5k views

Countdown timer in every table cell

I am making countdown app with multiple records, so I am using UITableView to show that records and countdown dates. What I do is just take one timer and reload cells on every second. Is this a best ...
4
votes
0answers
303 views

Unit Testing Against Exceptions

I am writing a Swift library. I'm writing unit tests for that library. I am afraid that some of the code that I am testing will possibly throw exceptions. In Swift, we can handle errors, but we can ...
4
votes
0answers
222 views

A general iterator to replace “non-standard” C-style for loops

Since the deprecation of C-style for loops in Swift 2.2 (and the removal in Swift 3), several questions about the possible replacements were asked on Stack Overflow. In most cases, a ...
3
votes
0answers
24 views

Swift iOS app for showing motivational quotes, with multiple screens

I'm one month into self-learning Swift, and I would like some advice to improve my coding skills. I have listed 2 situations that I think I need to improve. I'd like some feedback focusing on my use ...
3
votes
0answers
497 views

Applying Gaussian blur to UILabel

Here is the code and it is really slow, like seconds slow to render about 25 labels. ...
3
votes
0answers
103 views

Load data from WebAPI to the ViewController

My current code working perfectly, it is for data load from web api to the UIViewController (UITableView). But I am confused ...
3
votes
0answers
400 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 ...
3
votes
0answers
1k 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 ...
3
votes
0answers
142 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 ...
3
votes
0answers
171 views

Using the visitor pattern to compose notifications

I'm solving the following problem using the Visitor design pattern in Swift: When a quote is requested or an appointment is booked we send out an email to the customer, and build an internal ...
3
votes
0answers
2k views

Custom view for data input (in-app (non-system) keyboard)

I have made a custom keyboard that gets loaded from an .xib file. I decided to go with an in-app only keyboard rather than a system-wide keyboard because the documentation states: Make sure a ...
3
votes
0answers
5k views

Multiple View Controllers in a Single Window (Swift on OS X)

As an exercise I want to have a single window application (in Swift on Mac OS X) with 4 views, each controlled by an independent view controller and have their own XIB file. I have working code, but I ...
3
votes
0answers
407 views

“Extending” the Swift 2 ErrorType protocol

I am building a simple REST client in Swift 2. The methods the client offers can return errors. Every method returns the same errors (network problem, unauthorized, etc...). But each method can also ...
3
votes
0answers
121 views

Second attempt at Sierpinski Triangle App

I am a Java programmer trying to learn the ways of Swift. A few days ago, I posted the code for a very simple app that draws a Sierpinski triangle and implements a pretty buggy zoom. I was told to ...
2
votes
0answers
25 views

Basic network layer for a JSON API client

Just looking for some feedback/ways to improve this basic networking layer written in Swift. I'm still learning, please elaborate with as much detail as possible. ...
2
votes
0answers
20 views

Swift MVVM: Repositories - loading entities and dependency injection

I create a lexikon and a navigation for ZOO. I use MVVM architecture supported by ReactiveSwift. I have a few questions about my practises and whether I could write my repositories better and more ...
2
votes
0answers
16 views

Simplifying a firestore querying function

I have this function where it queries through the database and returns a random user if the requirement is met if not then try it again. It works and all but I feel like the code could be better/...
2
votes
2answers
209 views

Tableview Subclass implementing delegate datasource

I have two view controllers which have same tableview. One is for Post and one is for Profile, which also contains a post by a user. I have decided to reuse the code, so I have created the class ...
2
votes
0answers
105 views

Log in user through json and display the application

I am currently learning swift 4 and would like to ask you to correct my code. (I would like to have a pattern for learning the "beautiful code"). My code gets data from the server in JSON format and ...
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 ...
2
votes
0answers
155 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. ...
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 ...
2
votes
0answers
689 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 ...
2
votes
0answers
98 views

Private contexts and their parents in CoreData

I find myself following this pattern a lot in my core data code, which works, but I'm wondering if it is needed... ...
2
votes
0answers
181 views

Find MIDI devices with certain names and make them usable

I'm working on a Swift app for macOS, where I take input from MIDI devices and transform that input. The MIDI devices being supported come in for flavors. What my code does is scan for MIDI devices, ...
2
votes
0answers
40 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 ...
2
votes
0answers
711 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
0answers
872 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 ...
2
votes
0answers
52 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 ...
2
votes
0answers
479 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 ...
2
votes
0answers
58 views

Correct Swift Model for JSON

I am working on a program that would generate swift classes/ structures for JSON file contents. The link to the application is Json2Model in case you want to contribute directly. I do not know a ...
2
votes
0answers
104 views

didSimulatePhysics to animate a ball, taking 45% of CPU

According to my time profiler this is taking 45% of my cpu usage: have tried to optimize, and someone on stack overflow -- recommended to post here. Time profiler says 99% of the time is spent on the ...
2
votes
0answers
2k views

Expandable tableView cells

What I wanted to achieve is tableView with clickable cells, anytime somebody click a certain cell, another cell with picker, UITextField etc appears below, it's like a dropdown menu. When browsing ...
2
votes
0answers
275 views

Am I using ReactiveCocoa the “right” or most “purely functional” way in this Document class?

Introduction I am still learning both swift and ReactiveCocoa, and instead of directly applying it to one of my projects, I have instead worked a few hours on ...
2
votes
0answers
104 views

Parsing JSON with generics

I get back two dictionaries, I need to parse through them and put in an array two objects. I think I did a very poor job and I have a feeling there is a better way to make the code more compact and ...
2
votes
0answers
690 views

Interactive transition between view controllers

I have made an interactive transition controller in Swift in two different ways. This interactive transition controller is the parent class and I have few child classes which adapt the parent for ...