swift3 - Are Doubles Comparable in Swift -


swift 3, xcode 8β2.
i've implemented class sorts comparable data , attempted test using doubles. unfortunately, i'm getting error "cannot convert value of type '[double]' specified type '[t]'.". i've reproduced error in sample code below:

class foo<t: comparable> {     let data: [t]  = [double]() } 

am right assuming doubles comparable and, if so, how eliminate error above?
thx.

your property has generic type, t: can't declared holding concrete type. use [t] in declaration, , use double when instantiating class.

for example i've made property var modify it:

class foo<t: comparable> {     var data: [t] = [t]() }  let f = foo<double>() f.data = [42.0, 33.0] f.data.sort() print(f.data) 

gives

[33.0, 42.0]

as expected.


Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -