Swift: How to better format the output when using println with a tuple? -


i have defined function:

func need_rebalance() -> (bool, rebalancestrategy) {  } 

where rebalancestrategy enum type

enum rebalancestrategy: string {     case leftright = "leftright"     case rightleft = "rightleft" } 

when tried print way,

    println("need rebalance? \(self.need_rebalance())") 

i got output this:

need rebalance? (false, (enum value)) 

my questions are:

1) there easy extract value tuple? (hopefully similar python e.g. self.need_rebalance()[1]. apparently syntax not work in swift because tuple not support subscript())

2) how can print raw value of enum instead of having (enum value)?

i using xcode6 beta5

there's way extract value using tuple indexes, it's not nice, involves reflect:

let tuple = self.need_rebalance() let reflection = reflect(tuple) reflection[0].1.value // -> true reflection[1].1.value // -> rebalancestrategy.? 

also, if tuple members not named:

let tuple = self.need_rebalance() tuple.0 // -> true tuple.1 // -> rebalancestrategy.? 

to access raw value in enum:

rebalancestrategy.leftright.toraw() 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -