Swift return type clarification

后端 未结 4 1850
既然无缘
既然无缘 2021-01-29 13:05

I see a Swift function written as follows:

func calculation(imageRef: CGImage) -> (red: [UInt], green: [UInt], blue: [UInt]) {

 ...
 ...
}

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-29 13:39

    It's a tuple that this function is returning.

    A tuple can hold various types in one object, but unlike an array, you cannot append or remove objects to/from it.

    From Apple Developer Swift Guides:

    Tuples group multiple values into a single compound value. The values within a tuple can be of any type and don’t have to be of the same type as each other.

    Tuples don't exist in Objective-C. You can find more information about that here.

提交回复
热议问题