Overview
TheR2Object struct represents a file or folder entry retrieved from a Cloudflare R2 bucket. It includes metadata like size, modification date, and provides computed properties for display formatting.
Properties
Unique identifier automatically generated for each object
The full path/key of the object in the R2 bucket. Folder keys end with a trailing slash
/Size of the object in bytes. For folders, this is typically
0The last modification date of the object. May be
nil for some objectsFlag indicating whether this object represents a folder (true) or file (false)
The display name derived from the key. Returns the last path component with trailing slashes stripped for folders.Examples:
"documents/report.pdf"→"report.pdf""images/2024/"→"2024"
Human-readable file size formatted using
ByteCountFormatter. Folders display "--"Examples:1024→"1 KB"1048576→"1 MB"- Folder →
"--"
Human-readable last-modified date formatted with medium date and short time style. Returns
"--" if lastModified is nilExample: "Jan 15, 2024 at 3:45 PM"Source Code
R2Object.swift
Protocols
Identifiable- Has a uniqueidproperty for use in SwiftUI listsSendable- Thread-safe value type that can be safely passed across concurrency boundaries
Usage Example
Notes
- Folder objects typically have a trailing
/in their key - The
nameproperty intelligently handles both files and folders - All computed properties are designed for direct display in UI elements
- The struct is optimized for use in SwiftUI
ListandForEachviews viaIdentifiable