Swift using if on an enumeration resulting in an error not convertible to '_Arra...
source link: https://www.codesd.com/item/swift-using-if-on-an-enumeration-resulting-in-an-error-not-convertible-to-arraycastkind.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Swift using if on an enumeration resulting in an error not convertible to '_ArrayCastKind'
I'm using Beta 3 of xcode 6, and I am having a problem doing a simple if statement against an enum passed into an argument of a closure. Here is the simple enum definition:
enum FLSTeslaLoginStatus {
case LoggedOut
case LoggedIn
case LoggingIn
case LoginFailed(NSData!, NSHTTPURLResponse!, NSError)
}
And the code with the error is:
As you can see the switch statement works fine, but the if check is resulting in the error. This is just some test code so I won't normally have a switch and an if statement, but I'm trying to figure out what's wrong with the if statement. I'm thinking it is a compiler bug.
This is supported in Swift 2.0 with the use of "if case".
Swift 2.x allows this via the if case pattern match: https://www.natashatherobot.com/swift-2-pattern-matching-with-if-case/
if case let .LoggedIn(name,password) = status {
print( "\(name) Logged in!" )
}
Related Articles
Sorting in MySQL using a CASE expression shows results that I do not understand
Using #define Constants in Enumerated Data Types, Syntax Error
C # class ctor that receives a c ++ / cli object results in an error "not supported by the language"
Swift 2 Error: new () is not available in Swift: use object initializers instead
Init var with swift using SpriteKit?
PHP: Why is not the first record displayed when I use 'while' to display the results?
Multiplication matrix in swift using the frame Accelerate 32 bits vs 64 bits
Join 3+ tables using SQL displaying too many results
Swift using NSStatusBar statusItemWithLength and NSVariableStatusItemLength
Golang: Multidimensional array using a slice strategy slice, resulting in a strange output
linear regression using lm () - surprised by the result
Python Svmlight Error: DeprecationWarning: Using a non-integer instead of an integer will result in an error in the future
Using declarative_authorization to limit the results in the model
MySQL using Group By to limit results
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK