Saturday, 15 February 2014

save - Swift: Error saving UIColor to NSUserDefaults (CGFloat is not convertible to Float) -



save - Swift: Error saving UIColor to NSUserDefaults (CGFloat is not convertible to Float) -

i'm trying save rgb values of uislider getting next error:

'cgfloat' not convertible 'float'

private func savedisplaycolor() { var color = sliderview.backgroundcolor allow colors = cgcolorgetcomponents(color?.cgcolor) var defaults:nsuserdefaults = nsuserdefaults.standarduserdefaults() defaults.setfloat(colors[0], forkey:kfontselectedcolorr) defaults.setfloat(colors[1], forkey:kfontselectedcolorg) defaults.setfloat(colors[2], forkey:kfontselectedcolorb) defaults.synchronize() }

sorry i'm lost here. i'm seeing right values when do:

println(colors[0]) println(colors[1]) println(colors[2])

any help understand error mentioned , possible fix?

seems needed wrap cgfloat:

defaults.setfloat(cgfloat(colors[0]), forkey:kfontselectedcolorr)

save nsuserdefaults uicolor cgfloat

No comments:

Post a Comment