Balanced Parentheses in Strings

Today, I’d like to present a small algorithmic problem and some solutions I have come up with. The problem is as follows: Given a string, determine if the parentheses are balanced. Balanced parentheses mean that for every ( found, there must be a corresponding ) to balance it. Input and output It is guarantee that any given string will contain at least one parenthesis. in: "(hello" out: false in: "(hello()world)()" out: true in: "hello()(())" out: true in: "()" out: true in: "(" out: false Solutions Using a Hash Table (Dictionary) Let’s try a simple approach using a hash table.
Read more

Working With Git Submodules

The other day, I was working on a project that had a Git submodule. Initially, I found it a bit tricky to make it work, so I decided to create a short tutorial on this. What is a Git submodule Essentially, a Git submodule is a way to include one Git repository inside another Git repository. This creates a nested structure. So, in simple words, a Git submodule is like a mini Git repository that you can include in your main Git repository to use and update external code or resources without actually putting all of their files directly in your project.
Read more

Replacing Elements in a String

One of the most common problems we face when working with strings is modifying certain characters in the string. This problem can be easily solved with the use of regular expressions (regex). Before Swift 5.7 If you can’t uae the newest Swift you can achieve this by using the method replacingOccurrences(of:with:options). Here is an example of its use: let s = "12abc34" let t = ss.replacingOccurrences( of: "[a-z]", // regex with: "", options: .
Read more

SwiftUI – Horizontal Pages Carousel

Horizontal page carousels are a common element in iOS interfaces for presenting pages in a horizontal, swipeable format. They are particularly useful for showcasing views with varying content. Code In SwiftUI, creating such elements is straightforward. Let’s define a SwiftUIView and use the following code: import SwiftUI struct PageSliderView: View { // the data we want to present in each page, // this can be as simple as an array of string or as complex as an array of compound views.
Read more

Swift copy-on-write

To understand what copy-on-write means we need to delve into Swift’s type classification. Objects in Swift can be divided into two type groups: value types and reference types. The main difference between the two is how they are managed in memory. Theoretically, Value types create a new copy on memory each time they are assigned to a new variable, conversely reference types share the same reference amongst all variables. What is copy-on-write?
Read more