Swift struct with 'Any' not copied correctly into a function -
here's struct -
struct settingsitem { var id: string! var defaultvalue: any! init() { } }
then it's being used -
var item2 = settingsitem() item2.id = "abcd" item2.defaultvaule = "1234" f(item2) // <-- breakpoint shows item
when executed, item
looks @ breakpoint shown above. inside function f
, item
messed up.
func f(item: settingsitem) { println(item) // <-- bad item! }
it looks item isn't copied correctly when calling f
, when tried on playground didn't reproduce.
any ideas causes this?
update
it seems working when change type of var defaultvalue: any!
else, int!
or string!
.
also tried using default constructor (removed init()), didn't help.
why fail copy when using any
?
in xcode 6.4 same behaviour in playground too.
probably best not rely on built-in string-conversion functionality that’s debugging purposes. instead, try giving type explicit printable
implementation:
extension settingsitem: printable { var description: string { // make string whatever think appropriate // string representation of value return "{id: \(id), defaultvalue: \(defaultvalue)}" } }
if add this, prints out way inside f
.
p.s. i’d suggest thinking ways can remove !
, any
struct, lead problems in longer-term.
Comments
Post a Comment