swiftcore-nfc

Core NFC convert identifier Data into String


With the recent Core NFC updates you can now access the identifier from a miFare Tag.

This identifier is of type Data. How do you convert this data into its string value?

Many thanks


Solution

  • Regardless of the origin of Data, you can convert Data into String by using String(data: Data, encoding: String.Encoding). As for encoding, it would most likely be UTF8. So you can do something like this

    let identifierData: Data = //identifier data
    let stringValue = String(data: identifierData, encoding: .utf8)