6

Swift using if on an enumeration resulting in an error not convertible to '_Arra...

 2 years ago
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'

advertisements

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:

a5ToG.png

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

I'm building a small program that allows teachers to create exams from a bank of questions. The teacher can then sort the questions in the order that he/she would like them to appear on the exam. So I am trying to return a list of questions based on

Using #define Constants in Enumerated Data Types, Syntax Error

I am a bit puzzled by this error I get while trying to compile my MFC project. To simplify, I wish to enumerate something like this: enum Cars { Audi, Bmw, Ford }; Which works fine, but I get errors while compiling when I define any of the 'Cars' suc

C # class ctor that receives a c ++ / cli object results in an error "not supported by the language"

My solution has two projects: a C# exe and a cpp clr dll. Class1 and Class2 are cpp/clr classes implemented in the dll, and Class1's constructor expects a Class2 object: Class1(Class2 cl2) When I try to instantiate it in my C# class I get the followi

Swift 2 Error: new () is not available in Swift: use object initializers instead

2 working code under but when i checked it to swift 2 gives me this error : ViewController.swift:55:50: 'new()' is unavailable in Swift: use object initializers instead My all codes here override func viewDidLoad() { super.viewDidLoad() // Do any add

Init var with swift using SpriteKit?

How to correctly init with swift using SpriteKit? This compiles but I get a error once the simulator starts running. "swift_reportUnimplementedInitializer" import SpriteKit class GameScene: SKScene { var paddlePositionUpdate:CGPoint init(paddleP

PHP: Why is not the first record displayed when I use 'while' to display the results?

Why is the first record in my query not being displayed when I use 'while' to show the results? For example, user_id 1 logs in and the contact_id 5 and 6 are displayed with my echo at the end with: echo "contact is " . $row["contact_id"

Multiplication matrix in swift using the frame Accelerate 32 bits vs 64 bits

I am trying to do matrix multiplication in Swift using the Accelerate framework. Used the vDSP_mmulD. This worked perfectly in the iPhone6 , 6 plus, iPad Air simulator (all 64 bit architecture) but did not work with any of the 32 bit architecture dev

Join 3+ tables using SQL displaying too many results

im trying to create a query to join these tables together using this method below. However it is repeating results and they are not linking up correctly. as in the same rating comment would be on about 4/5 different results etc. its producing 18ish r

Swift using NSStatusBar statusItemWithLength and NSVariableStatusItemLength

I'm trying to rewrite the following code from the Status Bar Programming Topics in Swift. NSStatusBar *bar = [NSStatusBar systemStatusBar]; theItem = [bar statusItemWithLength:NSVariableStatusItemLength]; [theItem retain]; [theItem setTitle: NSLocali

Golang: Multidimensional array using a slice strategy slice, resulting in a strange output

I am using following simple code for 2d array in golang, where APPEND function is resulting in Duplicate values rather than appending. package main import "fmt" func main() { var n int fmt.Scanf("%d", &n) array := [][]int{} row :=

linear regression using lm () - surprised by the result

I used a linear regression on data I have, using the lm function. Everything works (no error message), but I'm somehow surprised by the result: I am under the impression R "misses" a group of points, i.e. the intercept and slope are not the best

Python Svmlight Error: DeprecationWarning: Using a non-integer instead of an integer will result in an error in the future

I'm running python 2.7.5 with scikit_learn-0.14 on my Mac OSX Mountain Lion. Everything I run a svmlight command however, I get the following warning: DeprecationWarning: using a non-integer number instead of an integer will result in an error >in th

Using declarative_authorization to limit the results in the model

I am using the declarative authorization gem for permissions in a rails project and I am trying to limit output from the model based on user permissions. My abbreviated authorization file looks like this: roles do role :supervisor has_permission_on :

MySQL using Group By to limit results

Okay, so I am trying to perform a query that has 4 tables, users, events, event_roles, user_event_role. The users can fill multiple roles. What i am trying to do is get a result that looks more like this: User, event, Role(s) So if user 'Bill' is ass

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK