是否可能,或者该函数是否需要声明为static
或class
?
class SimManager {
var particleSimulation: (inout Particle, Float) -> Void = updateParticles
func updateParticles(inout p: Particle, deltaT: Float) -> Void {
...
}
}
给出编译器错误:
SimManager.swift:36:63: Cannot convert value of type 'SimManager -> (inout Particle, deltaT: Float) -> Void' to specified type '(inout Particle, Float) -> Void'
最佳答案
将articleSimulation
的初始化移至类的指定初始值设定项。
class SimManager {
var particleSimulation: ((inout Particle, Float) -> Void)!
func updateParticles(inout p: Particle, deltaT: Float) -> Void {
}
init() {
self.particleSimulation = updateParticles
}
}
关于swift - 在 Swift 中将成员函数分配给成员变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35761465/