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
UUID
Unique identifier automatically generated for each object
String
required
The full path/key of the object in the R2 bucket. Folder keys end with a trailing slash
/Int64
required
Size of the object in bytes. For folders, this is typically
0Date?
The last modification date of the object. May be
nil for some objectsBool
required
Flag indicating whether this object represents a folder (true) or file (false)
String
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"
String
Human-readable file size formatted using
ByteCountFormatter. Folders display "--"Examples:1024→"1 KB"1048576→"1 MB"- Folder →
"--"
String
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