Enum




import UIKit


class ViewController: UIViewController {

    

    enum DocumentStatus: String, CaseIterable {

        case PENDING = "Pending"

        case APPROVED = "Approved"

        case REJECTED = "Rejected"

        case OVERDUED = "Overdued"

    }

    

    override func viewDidLoad() {

        super.viewDidLoad()

        

        let allEnumCases: [DocumentStatus] = DocumentStatus.allCases

        let allEnumCasesAsString: [String] = DocumentStatus.allCases.map { $0.rawValue }

        

        let indexOfDocumentStatusEnum: Int? = DocumentStatus.allCases.firstIndex(of: DocumentStatus.APPROVED)

        

        let indexOfDocumentStatusString: Int? = DocumentStatus.allCases.map { $0.rawValue }.firstIndex(of: "APPROVED")

        

        let statusEnumByString: DocumentStatus? = DocumentStatus(rawValue: "APPROVED")

        

    }

}



Comments

Popular posts from this blog

PUSH Notification

NotificationCenter