Compress String

Question A simple compression algorithm would be to replace repeating characters with their count. Example aaa --> a3 aaabb --> a3b2 aaabbaa --> a3b2a2 Want to stand out? Ask if there’s a difference between a & A and if you need to add uppercase & lowercase together or need to separate them. In my implementation I assumed they’re different. Code // start counting, then upon seeing a diff, write the count....

June 15, 2022 · 1 min

Check if Two Strings Are One Edit Away

Question You can edit a string in three different ways: insert, remove or replace a character. Write a function to see if two strings are one or zero edits away. Example like, like --> true (zero edits) like, likes --> true (one edit: remove/insert) like, life --> true (one edit, replace) like, lik --> true (one edit: remove/insert) like, pine --> false (two edits) like, lion --> false (two edits) Strategy For most questions that require you to return true or false, you can reduce the scope of the question by removing noise....

June 15, 2022 · 3 min

Swift Strings for iOS interviewing

This is bit of fast paced intro into Swift Strings. ASCII, Unicode and the challenges they introduce. ASCII Ages ago, only characters that existed were just a to z, A to Z, and bunch of other English characters. This was problematic. You were limited to only 7 bits i.e. only 2 ^ 7 - 1 = 127 characters. Also non-English characters where not part of ASCII. Literally the name says ‘American Standard Code for Information Interchange’....

June 12, 2022 · 7 min
dispose bag

CurrentValueSubject Example

I googled a bit for “CurrentValueSubject Example”. Surprisingly I wasn’t able to find a simple answer. So I created a few examples: Basic import UIKit import Combine class ViewController: UIViewController { var name = CurrentValueSubject<String, Never>("Jason") override func viewDidLoad() { super.viewDidLoad() setup() } func setup() { let _ = name.sink { value in print(value) // Jason, Jason Bourne } name.send("Jason Bourne") } } Basically every time you call send on a publisher, the subscriber gets a callback....

April 14, 2022 · 7 min

Whats the Difference Between Unowned and Weak References?

TIL I finally learned when to use unowned as opposed to using weak. Differences Under the hood: unowned is essentially a force-unwrap of a weak capture, with all that it entails. Because of this using it slightly more dangerous. Crash danger: Accessing an unowned reference while it’s nil will cause a crash. Compilation error: Every weak reference, must be an optional property. Otherwise you’ll get a compilation error: weak var delegate: DataEntryDelegate = DataHandler() // ERROR: 'weak' variable should have optional type 'DataEntryDelegate?...

March 11, 2022 · 3 min

Why can't Xcode show the caller?

Download the sample project if you want. You don’t have to though. The project doesn’t even need to be ran. It’s just provided for context. I’m going to discuss two gotchas I hade with Xcode. For quite some time I thought a fix was coming, then I realized this is because I didn’t fully understand the difference between an interface (or protocol) with a concrete type. Find Call Hierarchy not working: Have you ever right clicked on a function -> Find -> Find Call Hierarchy, but then wondered why Xcode doesn’t show you where the function is getting called from?...

January 4, 2022 · 3 min

Swift Protocol Compile Time Check

I always thought that if you just use {get} on a protocol variable, then you can still set it i.e. it doesn’t matter if you give it a setter or not. That’s not true. It really depends on which compiler checks come in to place. Compiler checks are different depending on the type you want a variable to be. Can you guess which of the two snippets will compile? Snippet A...

December 30, 2021 · 2 min