Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single-value-tuple as last member of struct in swift

MusicPlayer's API relies on variable length arrays as the last member of a struct to handle passing around data of unknown size. Looking at the generated interface for MusicPlayer, the structs used in this method present their last element in a single value tuple.

example:

struct MusicEventUserData {
    var length: UInt32
    var data: (UInt8)
}

I doubt that any of this has been officially exposed but has anyone figured out whether this syntax is a red herring or actually significant? I don't think that there is a means to hand arbitrarily sized things via swift but does this help when calling from C?

like image 979
griotspeak Avatar asked Jan 26 '15 04:01

griotspeak


1 Answers

after test on a playground I can see there is no difference between (Int) and Int type. Here is my tests :

func testMethod(param1: Int, param2: (Int)) -> Int{
    return param1 + param2
}

testMethod(2, 3) // return 5
testMethod(3, (6)) // return 9

About the calling in C, I just think it is a little bug on the bridging from ObjC to swift

like image 156
zarghol Avatar answered Oct 14 '22 14:10

zarghol