Skip to content

Toolkit enhancement proposal: Swift CustomStringConvertible and CustomDebugStringConvertible for AGS Objective-C Enums #34

@esreli

Description

@esreli

I would like to introduce a swift toolkit enhancement that would adhere AGS enums to the swift CustomStringConvertible and CustomDebugStringConvertible protocols.

This enhancement will allow someone to either:

  1. Help display to a user a stringified status
  2. Display to a developer a stringified debug status in the debug console

This will allow a developer to more easily convey information contained in an Objective-C enum (statuses, etc) to themselves or to the user.

For example:

extension AGSDrawStatus: CustomStringConvertible {
    
    public var description: String {
        switch self {
        case AGSDrawStatusInProgress:
            return "In Progress"
        case AGSDrawStatusCompleted:
            return "Completed"
        default:
            return ""
        }
    }
}

extension AGSDrawStatus: CustomDebugStringConvertible {
    
    public var debugDescription: String {
        return "[Draw Status] \(self)"
    }
}

let drawStatus:AGSDrawStatus = AGSDrawStatusInProgress

print(drawStatus)
// In Progress

print(drawStatus.description)
// In Progress

print(drawStatus.debugDescription)
// [Draw Status] In Progress

and

(lldb) po drawStatus
▿ [Draw Status] In Progress
  - rawValue : 0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions