Can not initialize GKNoise with a supposedly valid constructor

according to the following link:

https://developer.apple.com/documentation/gameplaykit/gknoise/1778280-init


the following constructor should combine several other GKNoises:

let combinednoise = GKNoise(componentNoises : [GKNoise](noisenew, noisenewnew), selectionNoise : noiseSource)

however, the playground returns a compilation error that says that this format is invalid.

Any help?

Accepted Reply

Your syntax for an array of GKNoise objects is incorrect. If you use "[GKNoise](…)" then you have to use valid constructor parameters inside the parentheses, and there is no Array constructor that takes two objects like that.


I think what you want is a literal array of GKNoises, which you can do like this:


let combinednoise = GKNoise(componentNoises: [noisenew, noisenewnew], selectionNoise: noiseSource)

Replies

Your syntax for an array of GKNoise objects is incorrect. If you use "[GKNoise](…)" then you have to use valid constructor parameters inside the parentheses, and there is no Array constructor that takes two objects like that.


I think what you want is a literal array of GKNoises, which you can do like this:


let combinednoise = GKNoise(componentNoises: [noisenew, noisenewnew], selectionNoise: noiseSource)

Thanks! Problem solved.