Access Memory Directly in Swift

Not just screens of numbers

Steven Curtis
5 min readSep 13, 2022

Difficulty: Beginner | Easy | Normal | Challenging

Swift is a memory safe language, but

To access the screenshot above in Xcode you can go through the menu Debug>Debug Workflow>View Memory and can choose an address to view, as well as the number of bytes.

Prerequisites:

Terminology

Pointer: An object that stores a memory address

UnsafePointer: A pointer for accessing data of a specific type

UnsafeRawPointer: A raw pointer for accessing untyped data. This means there is no type safety and no alignment

What am I looking at?

The image above showing the memory state of my machine (while running an App through Xcode) isn’t that easy to see.

So we can break it down.

The given memory address is 0x112f4a220, and (0 represents octal while x denotes hexadecimal).

0x112f4a220 in Hex is equivalent to the Decimal number 4612989472, and this is the first Denary number on…

--

--