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

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -