Microblogging for devs

This is a safe space to dump everything you have learned in bite-sized chunks.

Popular topics 🔥

Latest posts

display picture
Ray@ray·4d
When doing performance testing in XCTest, it helps to assert the N of any function / algo before running a performance measurement.

This ensures that if the test fails, it is not because of a higher N but of a more inefficient logic.
See full code
display picture
Ray@ray·5d
Principle of least astonishment (POLA):

When designing an interface (a component, an API), always design it in a way that the user will expect it to behave.

When creating a toolbar view it should ONLY contain functionality of a toolbar view, and not say, also handles logic to show a Settings view.
display picture
Ray@ray·5d
Likewise, l10n is called l10n because l_ocalizatio_n has 10 letters between l and n.
display picture
Ray@ray·5d
Fun fact, the reason why i18n is called i18n is because there are 18 characters in between i and n: i_nternationalisatio_n!
display picture
Ray@ray·5d
Every IOS app should be usable by everyone. Accessibility in IOS is done through Screen Readers. So placing accessibility modifiers **intentionally** matters a lot.

To do so, use the .accessibilityLabel and .accessibilityHint modifiers on your views to modify what the screen reader would read.
See full code
display picture
Ray@ray·5d
To pluralise a string, Swift has a convenient feature that hijacks your markdown.
See full code
display picture
Ray@ray·7d
@EnvironmentObject is like React's context provider. Rather than passing down data across view hierarchies (prop-drilling in React), we can define it once and access it across child views.

The example below shows how to initialise and share CoreData's viewContext on load:
See full code
display picture
Ray@ray·8d
ArrayList or a Linked List?

It depends. If you're doing stack-like operations, both will be fine. ArrayList might be slightly better because it offers indexing at constant time cost.

Queues with ArrayLists are bad, because we'll have to shift every item whenever we enqueue or dequeue.
display picture
Ray@ray·9d
Coming from Typescript, creating related types can get really messy and are usually organised via folders or naming conventions.

In Swift, we can just do nested structs:
See full code
display picture
Ray@ray·9d
NavigationLink and Sheets are 2 ways to show user new content. However, they should be used with the right intention:

1. NavigationLinks – for going deeper into a topic / user interaction
2. Sheet – for showing unrelated content.

Join Dweets to see more.