Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converting read data back to a string #43

Closed
OliverMardle opened this issue Nov 26, 2016 · 1 comment
Closed

converting read data back to a string #43

OliverMardle opened this issue Nov 26, 2016 · 1 comment

Comments

@OliverMardle
Copy link

Hi, I have sent a string to my iOS app which delivers fine, the string is "26" however the iOS app interprets it as [50, 54]. How do I convert this back into a string? I am reading it as let data = client.read(1024).

Thanks

@danshevluk
Copy link
Collaborator

Hey!

Here is the code:

let bytes: [Byte] = [50, 54] // Byte is a typealias for UInt8
let stringData = Data(bytes: bytes)
let string = String(data: stringData, encoding: .utf8) // "26"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants