Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to…

Follow publication

Member-only story

5 Powerful Ways to Leverage Enums in Swift

This is except for enums that are basic used.

Swift enumerations (enums) are a powerful feature that allows you to define a common type for a group of related values. Unlike enums in other programming languages, Swift enums are first-class types that can include sophisticated functionality.

1. Custom Enum Raw

I often use enums because they help keep my code organized. I use them to compare data types instead of using strings, which can be messy. In this example, I created an enum for my project because the API response data contains different keys that are also used as titles. This allows me to handle various types more effectively.”

Here, I also added functionality to capitalize the first letter.

enum IndicatorName: String {
case withNotation = "with notation"
case noNotation = "no notation"
case sector = "sector"
case companyQuality = "Company Quality"

var capitalized: String {
return self.rawValue.capitalized
}

var lowercased: String {
return self.rawValue.lowercased()
}

var uppercased: String {
return self.rawValue.uppercased()
}

var firstLetter: String {
return self.rawValue.capitalizeFirstLetterOnly()
}
}


public extension String {
internal func

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Published in Stackademic

Stackademic is a learning hub for programmers, devs, coders, and engineers. Our goal is to democratize free coding education for the world.

Responses (2)

Write a response

dalam enum ini and bisa menambahkan property, dari contoh ini adalah salah satu project yang saya kerjakan, pointnya adalah digunakan untuk enum yang mengguakan title dan image

What means « dalam enum ini and bisa menambahkan property, dari contoh ini adalah salah satu project yang saya kerjakan, pointnya adalah digunakan untuk enum yang mengguakan title dan image » ? 😳

--

I use the techniques shown here to create a whole new paradigm and architecture: https://medium.com/codex/a-new-coding-paradigm-declarative-domain-programming-cad35a3128fd

--