Access Enums in Swift more simple
See original GitHub issueAs I described here it is hard to access Java Enums from Swift. This can be done with:
var r:BISBTestTypeEnum = BISBTestTypeEnum.values().objectAtIndex(BISBTestType.Type1.rawValue) as! BISBTestTypeEnum
As you can see it is very long. It would be great if you could add one helper method to make such access more simple.
If you would add a method like this (Swift):
class func withValue(value: BISBTestType) -> BISBTestTypeEnum {
return BISBTestTypeEnum.values().objectAtIndex(value.rawValue) as! BISBTestTypeEnum
}
in Objective-C I guess that is something like this:
+ (BISBTestTypeEnum *)valueOfWithNSString:(BISBTestType *)value {
return [[BISBTestTypeEnum values] objectAtIndex:[value rawValue]];
}
you can access Enums as:
var r = BISBTestTypeEnum.withValue(BISBTestType.Type1)
Issue Analytics
- State:
- Created 8 years ago
- Comments:15
Top Results From Across the Web
Enumerations — The Swift Programming Language (Swift 5.7)
An enumeration defines a common type for a group of related values and enables you to work with those values in a type-safe...
Read more >Swift enums: An overview with examples - LogRocket Blog
Swift enums can be a powerful way to simplify your code. In this tutorial, we cover the basics of enums and how to...
Read more >Enumerations - a free Hacking with Swift tutorial
Enumerations – usually just called “enum” and pronounced “ee-num” - are a way for you to define your own kind of value in...
Read more >Five powerful, yet lesser-known ways to use Swift enums
A look at a few somewhat lesser-known ways in which enums can be used to solve various problems in Swift-based apps and libraries....
Read more >Using Enums in Swift. How to handle the constants, raw…
In Swift, you can set data types and values in Enums and define methods or properties on them. Also, using Codable, it is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Added --static-accessor-methods flag, which adds class methods to access static accessor functions and enum constants from Swift. This should now work:
var r:BISBTestTypeEnum = BISBTestTypeEnum.Type1()
@kstanger This issue is solved with your last fix.