简体   繁体   English

swift-声明计算属性以调用具有多个返回值的函数

[英]swift - declaring computed properties to call a function with multiple return values

I want to declare 3 computed properties that will call a function calculate that will return multiple values to the 3 computed properties. 我想声明3个计算属性,这些函数将调用函数calculate,该函数将向3个计算属性返回多个值。 ie fbound1, fbound2 and [displacement] as properties that take values from a function: "calculate" which returns 3 values. 即fbound1,fbound2和[displacement]作为从函数获取值的属性:“ calculate”,它返回3个值。

Code for calculate function with 3 return values 用于计算具有3个返回值的函数的代码

public func calculateBoundary (inout f:[Float], s:[Float], n:NSInteger) -> (forceBound1:Float, forceBound2: Float, displacement:[Float])

For example, i could declare a computed property that will call 'calculate' function with its return value to be initialized to the property. 例如,我可以声明一个计算属性,该属性将使用其返回值调用“ calculate”函数以将其初始化为该属性。

Declaring a computed property that will call calculate function with single return value 声明一个计算属性,该属性将调用具有单个返回值的calculate函数

var springDisplacement : [Float] {return calculate(forceView2, stiffView2, springNumView2) }

public func calculate (f:[Float], s:[Float], n:NSInteger) -> [Float]

这个怎么样?

let (forceBound1, forceBound2, displacement) = calculateBoundary(...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM