function - Error when using reduce() in Swift 2.0 -
note: applies swift 3.0
when attempt use reduce
function, error saying:
reduce unavailable: call 'reduce()' method on sequence
i figured out how enumerate()
function cannot seem solve issue. here line of code returning error:
var hashvalue: int { return reduce(blocks, 0) { $0.hashvalue ^ $1.hashvalue } }
you fix same way fixed problem enumerate()
. in swift 2, reduce has been removed global function , has been added instance method on objects conform sequencetype
protocol via protocol extension. usage follows.
var hashvalue: int { return blocks.reduce(0) { $0.hashvalue ^ $1.hashvalue } }
Comments
Post a Comment