[swift-evolution] Low-level Swift

Brent Royal-Gordon brent at architechies.com
Thu Jan 7 14:33:44 CST 2016

> - Is it possible to embed raw binary data in Swift? For example, an equivalent of the following C code "const int8_t foo[6] = {0x00,0x11,0x22,0x33,0x44,0x55};"? The simple Swift equivalent, "let foo: [Int8] = [0x0,0x1,0x2,0x3,0x4,0x6];" is obviously wildly different. Being able to embed raw binary data is very important in a low-level environment: for example, you may need to feed specific data to a device for an initialization sequence at a point where you don't have a filesystem available yet.

The raw binary data equivalent is a tuple. For instance, I believe this will have the exact memory layout you're looking for:

	let foo: (Int8, Int8, Int8, Int8, Int8, Int8) = (0x00, 0x11, 0x22, 0x33, 0x44, 0x55)

> There might be other aspects that I'm overlooking right now, but I think that's enough to start a discussion: is Swift really meant to be a systems programming language?

I think it's probably more accurate to say that Swift *aspires* to be a systems programming language. It is already fast enough and has low enough overhead, but some of the features needed aren't there yet, and aren't considered a priority over more common use cases like application programming.

Brent Royal-Gordon

More information about the swift-evolution mailing list