Skip to content
No description, website, or topics provided.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


This is a simple framework containing operators to make it easier to use pointers in swift.

pointee tries to make swift pointers more similar to familiar C style pointers. It allows you to use the familiar operators such as & and * (just on the other side) and allows you to cast using |> and |>>.


the pointee framework turns this:

let raw = UnsafeMutableRawPointer(&int)
let opaquePtr = OpaquePointer(raw)
let ptr = UnsafeMutablePointer<Int>(opaquePtr)


into this:

print((int& |> Void.self |> Int.self)*)


See main.swift for docs on all the operators. The different operators are:



Assigns a value to an UnsafeMutablePointer Example:

// ptr: UnsafeMutablePointer<Int>
ptr *= 1

Values and refrences


Create pointer of type. The allocation size of the pointer is determined using MemoryLayout. Example:

let ptr = Int.self*
// ptr: UnsafeMutablePointer<Int>


Get value of an UnsafeMutablePointer. Example:

// ptr: UnsafeMutablePointer<Int>
ptr *= 1
print(ptr*) // 1


Create pointer from value. Example:

let int = 1
let ptr = int&



Deallocate pointer. Example:

// ptr: UnsafeMutablePointer<Int>

Note: this should only be used on allocated pointers, for example:

var int = 1
var ptr = Int.self*
-ptr // Okay
ptr = int&
-ptr // Bad


Deinitialize and deallocate pointer. Example:

// ptr: UnsafeMutablePointer<Int>

Obviously the same note as above also applies here.


|> Using OpaquePointers:

var int = 1
var ptr = int&
ptr |> Double.self

|> to a void (aka raw) pointer:

var int = 1
var ptr = int&
ptr |> Void.self

Whats the difference? Instead of casting to an UnsafeMutablePointer<Void> it casts to an UnsafeMutableRawPointer.

|>> Bitcasting

Same syntax as above, just use |>>. This will use the unsafeBitCast method instead of using an OpaquePointer.


var foo = Foo() // Create instance of `Foo` += 2

let rawPtr = foo& |> Void.self // Cast to Void poiner (aka raw pointer)
var fooClassPtr = rawPtr |> Foo.self // Cast back to `Foo` pointer

// Chain casting
let bar = fooClassPtr
    |> Foo.self
    |>> Void.self
    |> Int.self
    |>> Void.self
    |> String.self
    |>> Int8.self

print(bar*) // 3 - gets the value of `bar`
bar *= 4 // which we can then set

print(fooClassPtr*) // Foo(bar: 4)

fooClassPtr = rawPtr |>> Foo.self // BitCast `rawPtr` back to `Foo` pointer += 3

print(fooClassPtr*) // Foo(bar: 7)


I created this mostly as a fun project but, it might also make it easier to communicate with C code.


You can use carthage to install this framework:

github "pudility/pointee"
You can’t perform that action at this time.