Created
August 3, 2016 09:00
-
-
Save Gernot/604f295786100e7b7b629ea282771889 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CharacteristicValue { | |
let format: Int8 | |
let exponent: Int8 = -1 | |
let unit: UInt16 | |
let namespace: Int8 | |
let descriptionInfo: Int16 | |
} | |
var value = CharacteristicValue(format: 14, unit: 0x272F, namespace: 1, descriptionInfo: 0) | |
//This works | |
let oldData = NSData(bytes: &value, length: sizeof(CharacteristicValue.self)) | |
//This gives me "Ambiguous Use of 'init'" on the `UnsafePointer` part. | |
let newData = Data(bytes: UnsafePointer<UInt8>(&value), count: sizeof(CharacteristicValue.self)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mzaks: Good point. I briefly considered
strideof
but for some reason assumed that it would be wrong to use it for a single struct (I guess because I implicitly assumed the padding bytes at the end could cause a problem). But that's not the case. /cc @Gernot