Category: Reference


Master map, compactMap, flatMap, reduce and filter by creating your own implementation

February 21, 2018

General Coding, Playground, Reference

Comments Off on Master map, compactMap, flatMap, reduce and filter by creating your own implementation


There are a few higher-order functions for collections that can be rather difficult to fully understand. While there are several good resources out there to learn the basics, it can still be confusing and seem a bit like magic. And when things seem like magic they tend to not get used effectively or maybe not at all.

In this post, I’m going to try explaining map, compactMap, flatMap, reduce and filter by walking through their inputs, outputs and deriving an implementation for each. For simplicity, we will focus on arrays but this can be expanded to most data structures. The goal is only learning the ideas, not to implement the best possible solution.Read More »


Beyond 128-bit integers

December 24, 2017

General Coding, Reference

Comments Off on Beyond 128-bit integers


I just finished a post related to the top range of integer values that are supported by Swift.

https://kenb.us/big-integers

The conclusion was that we can use the Decimal type to hold integer values with up to nearly 128 bits. That’s an impressively large number.

It’s hard to imagine a case where you would require both a larger number and precision at the least significant figures. However, it does make an interesting exercise so let’s give it a shot.

Read More »


How to store large integer values without losing precision

December 23, 2017

General Coding, Reference

Comments Off on How to store large integer values without losing precision


I recently wanted to use some very large numbers in Swift and quickly came across some limitations.

 

Int

My first implementation started out naively with Int (Int64) type. This is, after all, the easiest way to use integers.

The limitations are also easy to understand.
Read More »


3 ways to extract numbers from a string

December 3, 2017

General Coding, Performance, Reference

Comments Off on 3 ways to extract numbers from a string


I’m working on a project which requires me to parse some data that was formatted more for readability than parsing. Similar to NSStringFromCGRect which outputs in the format¬†“{{x,y},{width,height}}”

let rect = CGRect(x: 124, y: 387, width: 74, height: 74)
let text = NSStringFromCGRect(rect)
// "{{124, 387}, {74, 74}}"

This string can easily be read back again using it’s counterpart function¬†NSStringFromRect.

let text = "{{124.123, 387}, {74, 74}}"
let rect = NSRectFromString(text)

Read More »


How to get UITextView to behave like UILabel

November 20, 2017

Reference, Text, UIKit

Comments Off on How to get UITextView to behave like UILabel


UILabel and UITextView both rely on TextKit to render text. So why do they behave differently and how can they work together?

Below is a view with a UILabel (blue) and two UITextViews (red) laid out in IB.

The Label is constrained to the top right corner of the view and uses it’s intrinsic content size to determine the width and height. The size of the label matches closely to the size of the text.

Read More »

Starting a new iOS project

November 19, 2017

Reference

Comments Off on Starting a new iOS project


Most of this is going to be rather straight forward. Most developers will have done this plenty of times. So why bother writing about it? In my case, there are several things that I tend to do for most projects. I find that, if don’t do these things up front, I’ll usually end up in a place that I’ll need to do it at that time. These steps don’t always need to be done at the start of the project and some projects don’t require every step.

This is an attempt at creating a repeatable process that can work for the majority of projects.
Read More »


Subscribe via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.





Swift Tweets