Questions tagged [swift]

Swift is a general-purpose, multi-paradigm, compiled programming language developed by Apple Inc. for iOS, iPadOS, macOS, watchOS, tvOS, Linux, and z/OS.

Filter by
Sorted by
Tagged with
3
votes
1answer
265 views

Minimum window substring - LeetCode challenge

Below is my code for the “Minimum Window Substring” LeetCode problem in Swift: Given a string S and a string T, find the minimum window in S which will contain all the characters in T in complexity O(...
1
vote
1answer
47 views

macOS: resetting balance to center (0.5) using Swift

Due to some bug somewhere, my speaker balance kept moving off-center and it was getting annoying. So I cobbled together the code below (based on this question) which—to my surprise—does compile and ...
4
votes
1answer
71 views

How to properly decode a JSON dictionary into different Swift classes using Decodable and JSONDecoder?

Generally, the approach I've taken is to try calling container.decode from a decodable enum with its associated value returning ...
0
votes
3answers
138 views

Convert first letter of every word to uppercase

I am learning swift and I came across this problem. Converting each start letter to capitalized form if it's lowercase. ...
4
votes
2answers
86 views

Better way to provide data to UIKit component from Combine pipeline

Today I'm researching how to provide data to UIKit component when using Combine pipeline. I could see tons of tutorials about how to use SwiftUI + Combine from internet, but not found anyone helpful ...
3
votes
1answer
54 views

Granular vs a aggregated tests when dealing with arrays

I write code in a Test-Driven way and I often build my functions starting with tests for the easy edge cases. For example, given a flat array of Items that have a <...
10
votes
1answer
21k views

Pure Swift solution for socket programming

I have spend quite some time now to find out how exactly to do socket programming in Swift (Xcode 6.1). There are a few examples out there, but most of them no longer work for the latest release of ...
1
vote
2answers
69 views

How to load and get data from 2 files

I want to load 2 files and show this data in 2 strings. I trying to do it like this and it works fine. But I think it is not the best solution... How to do more elegant solution? ...
1
vote
1answer
60 views

Improving sqlite3 code in swift using c api

Trying to come up with a pattern where the code to open db, writing queries is elegant and clean while handling all possible error conditions. Following code ...
4
votes
1answer
129 views

JSON parsing service

I created the following service for the purpose of sending in a file for parsing. I'm using the generics so that when I call parse() I can pass a custom type ...
0
votes
1answer
62 views

Sqlite select and delete operation using C API in Swift

I've following sqlite code using C api within Swift having a read and a delete operation for review. For those not familiar with Swift, defer will execute after the ...
2
votes
0answers
37 views

A Daily goals list 'Dopamine Box'

Inspired by Mike Boyd's 'Dopamine Box' video: link, I decided it would be a good project to pursue by myself in swift. The end goal is to make it look like the box in the video, with switches and a ...
2
votes
2answers
94 views

Convert C to Swift

I trying to convert this C code for calculating distance from RSSI to Swift code. I try to do it by myself, but considering I'm beginner, I need help in how to do it. Here is C code: ...
2
votes
1answer
65 views

Display a Text() with a foreground color based on a condition

I decided to write a simple tab bar for macOS using Swift. tabs.swift ...
1
vote
1answer
62 views

iOS: prettify random color for debugging

iOS: prettify random color for debugging I used to use random color to debug, from colors I like ...
4
votes
3answers
17k 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 ...
10
votes
2answers
2k 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
0answers
57 views

Create buttons with MVVM architecture

im trying to migrate my very large swift view controller to mvvm but it still feels very large, can you guys give me any advice What this controller does is simple it shows a UIView on which i can ...
0
votes
1answer
121 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) ...
2
votes
1answer
99 views

UIView position updates based on device motion via RxSwift

I've created a simple function to work as a level, where the dot on screen is centered when the device is completely flat. It changes position based on device orientation. I use RxSwift to update the ...
47
votes
0answers
1k 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 ...
4
votes
1answer
90 views

Decoding indeterminate types using JSON Decoder

I'm working with a REST service that responds with indeterminate types. In particular, it can respond with a String, a correct payload (...
3
votes
1answer
48 views

Swift iOS rewrite a function that use Firebase database without updating a global variable

I'm learning swift programming and i built a music trivia app for iOS that use firebase real time database. I have a function that before the game start get the number of record for each category of ...
5
votes
1answer
349 views

Using Grand Central Dispatch to fetch data from Parse.com and update UI asynchronously

This works, and the UI is snappy in the simulator, but since this is my first time really using GCD, I'd just like this code to be reviewed before I start using it everywhere. Note that this is ...
2
votes
1answer
353 views

Retrieving creation date from Parse.com data

I got to show the createdAt date in a message timeline, I tried to make a separate array only for dates, but don't know if it is the right path to follow. It seems ...
2
votes
0answers
416 views

Adding a constraint to a PFQuery on a PFRelation with objects that have already been gotten

For some background, I am learning from the following Stack Overflow question that I asked regarding creating the this code. I was playing around with different combinations of ...
3
votes
1answer
97 views

Check if objects have coordinates

Here's a function: ...
8
votes
1answer
9k views

Star Rating in Swift

So I needed a a star rating feature to appear in my app - it doesn't need to be interactive. I have my app connected to a database I've set up in Parse, and I've made a column for OurRatingof type ...
5
votes
1answer
1k views

Updating number of votes with a “Like” button

I have a "Like" button in my iOS app that updates the votes every time it's tapped. Just like Facebook, Instagram, ProductHunt, etc. I have a custom cell where that ...
5
votes
1answer
193 views

Optimize Data Sending/Querying to Parse Swift iOS

I have a swift method that I'm using to update Parse in the backend when the button is tapped. Votes are being updated: The method acts as a voting system, incrementing a label every time it's tapped. ...
3
votes
1answer
681 views

Image Scrolling in UITableView with Parse

I'm trying to create an app that is scalable. One of the main features of the app is to view images from a database to a UITableView. Here is my code: ...
1
vote
1answer
37 views

“Pick up” images when tapped on and keep track of it

Trying to get my first job as a developer I made an app I was extremely proud of: https://github.com/AnatolyRudenko/Crystals.Dragons The game starts in a random room of a random maze. Some prebuilt ...
3
votes
2answers
284 views

Using enum to create, subscript and loop an array of structs in Swift 5.0

I'm trying to "build" a few "spaceships" in my code. I'm feeling it's a good idea to enumerate all the spaceships and use that as a subscript to build and use an array that holds the spaceships' ...
2
votes
0answers
52 views

Which is better-way to casting model

I need to convert my model to fit data in tableview cell finding better approach ...
5
votes
1answer
246 views

Sorting JSON items from a site

So I recently applied to this job for iOS Developer and was invited to complete the following code challenge: As a next step, please complete this coding exercise in order to proceed with our ...
2
votes
1answer
71 views

Projecteuler.net Problem 2 using collection pipeline Pattern

I solve projecteuler.net Problem 2 deferent way Generate number from 1 to range ex 100 and get the even number Get Fibonacci numbers from list Reduce array I have one problem with a large set of ...
1
vote
0answers
159 views

Simple bruteforce algorithm in Swift

So, I am learning Swift and as a little exercise I tried to implement a BruteForce algorithm. That algorithm is pretty simple however it is a bit slow too... Well, I am new to Swift, so maybe some ...
3
votes
2answers
65 views

A Start button handler

I was told my code contains a lot of force unwrapping. I thought it's okay to do that if I am sure that the value operated won't be nil: ...
3
votes
1answer
63 views

Break music player into usable components in SwiftUI

I created a music player using swiftUI.I need to ask a question when I break up my player into usable components. How should I take this approach with the music player? because the music player is one ...
3
votes
1answer
128 views

SwiftUI Dot indicator

I want to understand if I got this concept correctly. I should start work from ViewState; a reference type object holding the state of a view. Here it is called <...
1
vote
1answer
63 views

Swift NSCache Singleton

I want to wrap NSCache in a Singleton in order to use dependency injection in my code. This has resulted, rather unfortunately, in passing the type through a function parameter, and I even need two ...
1
vote
1answer
58 views

Generic memoize function in Swift

I need to perform some expensive calculation, such as determining a Fibonacci number: ...
1
vote
2answers
774 views

A scalable way to remove duplicates from Arrays without extensions in Swift 4

This method is an attempt at removing duplicates from arrays without the use of extensions. ...
1
vote
0answers
23 views

Plugin architecture to extend/customize behavior of white label swift based application

I have a white label swift based application in which I need to change behavior depending on the customers. I would like to add that behavior in a dedicated framework in classes/struct that would be ...
5
votes
1answer
99 views

Binding ViewModel to ViewController using RxSwift

I have a ViewController and ViewModel. Here I am using the .subscribe() method too many ...
2
votes
0answers
73 views

Swift Struct-based Factory Pattern

Edit: I added another configuration vector to CardView, a size attribute, which may be .small or ...
2
votes
3answers
123 views

I want to take away WebService call from UIViewController

I am using Moya to make network calls in Swift. In my ViewController I am calling the WebService and creating a model from response. ...
4
votes
1answer
253 views

Rock Paper Scissors in Swift

I'm going through the eBook Intro to App Development with Swift by Apple and I am making the Rock, Paper, Scissors app in lesson 20. This is the assignment that I got: [...] Name the enum ...
2
votes
1answer
103 views

Trie implementation for strings in Swift

A trie for handling strings for an autocomplete dictionary. This passes my fairly casual tests, though it's always possible that there are broken edge cases, but I'm mainly concerned about design and ...
2
votes
1answer
255 views

MVVM-C Swift with Dependency injection

I want to create a MVVM-C project, but also adequately test it. Naturally I want to create such a project that can access a Network Service. Any comments or thoughts on this approach? ...

1
2 3 4 5
13