RSSAmplifier

Blog

Swift by An Tran

A personal space to share what I am learning and doing.

antran.appRSS feed ↗97 posts

Latest posts

With AI, I can just build things!

Over a decade ago, when I was building my own startup, I wrote the backend, built the web frontend and deployed the servers, created the iOS…

Why Everyone Should Create Their Own To-Do List Apps (or Systems)?

In the age of productivity tools and apps, the to-do list remains a timeless cornerstone of getting things done. But here’s the twist: there…

iOS Interview - Leetcode 448. Find All Numbers Disappeared in an Array

Leetcode: 448. Find All Numbers Disappeared in an Array Naive solution Primary idea: Check every number between 1 .. n if they are in the…

iOS Interview - Leetcode 128. Longest Consecutive Sequence

Leetcode: 128. Longest Consecutive Sequence Naive Solution Primary idea: Sort the array, remove duplicated elements then iterate through the…

[SwiftUI] Use NSColorWell in SwiftUI macOS apps

While upgrading my inde app SimRecorder, I need to create a Color Picker view. Apple has introduced the ColorPicker view since iOS 14, macOS…

[SwiftUI] Observing scroll offset of a List

I’m doing some design explorations for my Minimalist Phone app. I’m trying to observe the scroll offset of a SwiftUI List. This is useful to…

Minimalist Phone: A minimalist to do app

Minimalism I have been an active practitioner of minimalism for a long time. My minimalism journey began when a friend gifted me a book…

How to render dynamic Markdown strings in SwiftUI?

SwiftUI has supported rendering Markdown texts natively recently, and it’s a great convenience to quickly render formatted texts using View…

Swift snippet to create a pie chart using CAShapeLayer and UIKit

This Swift code snippet is a minimal runable code that renders a pie chart using CAShapeLayer and UIKit. Code PieChartsView Sample…

Swift snippet to create a pie chart using Charts library

This Swift code snippet is a minimal runable code that renders a pie chart using the Charts library. Code Result

Swift snippet to create a bar chart using Charts library

This Swift code snippet is a minimal runable code that renders a combined bar and line chart in the same canvas using the Charts library…

iOS Interview - Leetcode 347. Top K Frequent Elements

Leetcode: 347. Top K Frequent Elements Naive solution using dictionary Primary idea: Use dictionary to count frequency of all elements, sort…

iOS Interview - Leetcode 102. Binary Tree Level Order Traversal

Leetcode: 102. Binary Tree Level Order Traversal Solution with Queue Primary idea: use a queue to help hold TreeNode, and for each level add…

iOS Interview - Leetcode 15. 3 Sum

Leetcode: 15. 3 Sum Primary idea: use the Two Pointers to find the remaining 2 indexes that fulfil the requirement Time Complexity: O(n^…

Heap data structure

A heap is a specialized tree-based data structure that satisfies the heap property. There are two types of heaps: Max-Heap: In a max-heap…

iOS Interview - Leetcode 3. Longest Substring Without Repeating Characters

Leetcode: 3. Longest Substring Without Repeating Characters Solution Primary idea: Dynamic sliding window tracking the last occurences of…

iOS Interview - Leetcode 973. K Closest Points to Origin

Leetcode: 973. K Closest Points to Origin Naive solution Primary idea: Calcualte the distances of all points, sort the result and pick the…

Use FFmpeg to speed up iOS Simulator recordings

Intro At work, I usually attach a record video for my features from iOS Simulators to my merge requests. This demo video has many advantages…

iOS Interview - Leetcode 542. 01 Matrix

Leetcode: 542. 01 Matrix Native Solution Primary idea: breadth-first search Time Complexity: O(n^2*m^2) Space Complexity: O(n*m) Optimised…

iOS Interview - Leetcode 57. Insert Interval

Leetcode: 57. Insert Interval Solution Primary idea: Insert not overlapped and overlapped intervals subsequently. Time Complexity: O(n…

iOS Interview - Leetcode 53. Maximum Subarray

Leetcode: 53. Maximum Subarray Solution Primary idea: Dynamic Programming, each element should be either with previous sequence or start a…

iOS Interview - Leetcode 217. Contains Duplicate

Leetcode: 217. Contains Duplicate Primary idea: Use a hash table to count frequency of all numbers in the array. Time Complexity: O(n) Space…

iOS Interview - Leetcode 104. Maximum Depth of Binary Tree

Leetcode: 104. Maximum Depth of Binary Tree Primary idea: Use DFS to calculate max depth of left and right node from the parent node. Time…

Move SimRecorder from Mac App Store to Self Publishing, 50% discount code: WWDC24

Recently, I have to move my app SimRecorder from Mac App Store to self publishing due to limitation of sandboxing. My app interacts with…

iOS Interview - Leetcode 876. Middle of the Linked List

Leetcode: 876. Middle of the Linked List Primary idea: Slow and fast pointers, where fast pointer moves 2 steps and slow point moves 1 step…

Testing Xcode 16 and macOS Sequoia

macOS Sequoia and Xcode 16 are the hot new softwares that have recently been released in the WWDC 2024 For Apple-platform software…

iOS Interview - Leetcode 543. Diameter of Binary Tree

Leetcode: 543. Diameter of Binary Tree Primary idea: DFS to calculate the max depth of the current node. Compare and update the global…

iOS Interview - Is static var thread-safe?

Is static var thread-safe? I have recently got this question in an interview. Is the following code thread safe? Let’s analyse the code a…

iOS Interview - Unowned referencing in Swift

I have got an interview question about recently. While I can answer it correctly, I was struggling a bit when the interviewer asked me…

iOS Interview - Leetcode 67. Add Binary

Leetcode: 67. Add Binary Solution Primary idea: Math: use carry and iterate from last to start Time Complexity: O(n), as we need to iterate…

iOS Interview - Leetcode 169. Majority Element

Leetcode: 169. Majority Element Primary idea: Boyer-Moore Majority Voting Algorithm Time Complexity: O(n), As two traversal of the array, is…

Avoid wasting CI resources with selective testing and pre-commit hook

My friend Tuan Hoang has recently published a very nice blog post about selective testing in iOS. Tokopedia team has also published a very…

iOS Interview - Leetcode 206. Reverse Linked List

Leetcode: 206. Reverse Linked List Primary idea: Iterate over the list, reverse the nodes and return the new head node. Time Complexity: O(n…

iOS Interview - Leetcode 409. Longest Palindrome

Leetcode: 409. Longest Palindrome Primary idea: Count number of character with even and odd frequencies. Adjust the final result depending…

iOS Interview - ARC in iOS vs Garbage Collection in Android

I have just got this question in a job interview recently: Compare memory management mechanisms between Android and iOS. I know the…

[SwiftUI] Custom bindings in ForEach/List loops

I have recently got an interesting challenge when developing my latest app Quick Drop. I’m writing this short blog post to explain how to…

iOS Interview - Leetcode 70. Climbing Stairs

Leetcode: 70. Climbing Stairs Naive Solution Primary idea: Recursion to calculate fifibonacci sequence Time Complexity: O(2^n), because at…

iOS Interview - Leetcode 41. First Missing Positive

Leetcode: 41. First Missing Positive Naive Solution Primary idea: Use Set to keep the positive numbers from the array and find the first…

iOS Interview - Leetcode 278. First Bad Version

Leetcode: 278. First Bad Version Primary idea: Binary search, adjust left and right pointers to narrow down the search space by checking if…

iOS Interview - Leetcode 383. Ransom Note

Leetcode: 383. Ransom Note Primary idea: Matching character frequencies between 2 string Time Complexity: O(m + n) Space Complexity: O(n)

iOS Interview - Leetcode 232. Implement Queue using Stacks

Leetcode: 232. Implement Queue using Stacks Primary idea: Use an array as stack Time Complexity: O(n) Space Complexity: O(n)

iOS Interview - Leetcode 141. Linked List Cycle

Leetcode: 141. Linked List Cycle Primary idea: Floyd’s Cycle Finding Algorithm: 2 pointers, slow and fast. slow pointer advances one step at…

[SwiftUI] How can you use onTapGesture for the entire row in a ForEach loop?

While working on a new feature for my QuickDrop app, I encounter an intersting challenge regarding to the . The clickable area is not the…

iOS Interview - Leetcode 110. Balanced Binary Tree

Leetcode: 110. Balanced Binary Tree Primary idea: Checking max depth of left and right node from the parent node and compare them. Time…

iOS Interview - Leetcode 235. Lowest Common Ancestor of a Binary Search Tree

Leetcode: 235. Lowest Common Ancestor of a Binary Search Tree Primary idea: Recursively check from root to find the common accestor of p…

iOS Interview - Leetcode 733. Flood Fill

Leetcode: 733. Flood Fill DFS Primary idea: DFS BFS, starting from the starting node and checking the 4 neighbour nodes recursively. Time…

iOS Interview - Leetcode 704. Binary Search

Leetcode: 704. Binary Search Primary idea: Binary search, adjust left and right pointers to narrow down the search space by comparing the…

Fix Xcode losing references to downloaded Simulator runtimes

Recent versions of Xcode have changed how they manage Simulator runtimes. The Xcode binaries become smaller because users will have to…

iOS Interview - Leetcode 242. Valid Anagram

Leetcode: 242. Valid Anagram Primary idea: Compare the character freequencies of the 2 arrays Time Complexity: O(n) Space Complexity: O(n)

iOS Interview - Leetcode 121. Best Time to Buy and Sell Stock

Leetcode: 121. Best Time to Buy and Sell Stock Primary idea: Dynamic programming, iterate through the prices and update the minimum price…