casting - Swift compiler error contradicts warning when declaring lazy property -
var rawdata: nsdictionary! lazy var nativedata: nativedata? = { return nativedata(jsondictionary: self.rawdata [nsobject : anyobject]) }()
results in error:
'nsdictionary!' not convertible '[nsobject : anyobject]'; did mean use 'as!' force downcast?
ok then...
lazy var nativedata: nativedata? = { return nativedata(jsondictionary: self.rawdata as! [nsobject : anyobject]) }()
which gives warning:
forced cast 'nsdictionary!' '[nsobject : anyobject]' succeeds; did mean use 'as'?
interestingly if remove lazy
, declare nativedata
regular optional, can as
cast fine:
obj.nativedata = nativedata(jsondictionary: obj.rawdata [nsobject : anyobject])
is bug in compiler? (xcode 7.3 (7d175))
update
it gets stranger. here's contained case.
// // a.swift // import foundation class nativedata { init(jsondictionary: [nsobject : anyobject]) { } } func == (lhs: a, rhs: a) -> bool { return lhs.id == rhs.id } class { var id: int64 = 0 var rawdata: nsdictionary! lazy var nativedata: nativedata? = { return nativedata(jsondictionary: self.rawdata [nsobject : anyobject]) }() }
if remove func ==
operator definition, compiler error goes away. (in actual code, a
conforms equatable
.) note error doesn't occur if put code in playground.
Comments
Post a Comment