ios - Exhaustive condition of switch case in Swift -


the apple documentation says

every switch statement must exhaustive. is, every possible value of type being considered must matched 1 of switch cases.

so in new xcode have placed code this

println(uint16.min); // output : '0' println(uint16.max); // output : '65535'  var quantity : uint16 = 10;  switch quantity { case 0...65535: //or case uint16.min...uint16.max:     println(); default:     println(); } 

now if remove default section compile error showing switch must exhaustive

so question case have mentioned case 0...65535: have not mentioned case values uint16 ?? still getting error ?? why getting error, did miss ??

swift verifies switch block exhaustive when working enum types. switching on bool requires default block in addition true , false:

var b = true switch b { case true:  println("true") case false: println("false") } // error: switch must exhaustive, consider adding default clause 

with enum, however, compiler happy @ 2 cases:

enum mybool {     case true     case false }  var b = mybool.true switch b { case .true:  println("true") case .false: println("false") } 

if need include default block compiler's sake don't have do, break keyword comes in handy:

var b = true switch b { case true:  println("true") case false: println("false") default: break } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -