I am trying to display a JPEG image from binary data that I am passing from a remote server. I have seen tutorials on how to convert an image already given as a JPEG to data then back to an image, but here is an issue where I have the binary data as a string. I am having trouble converting that string to the Data type so I can display it as an image. How can I convert my string to data?
My Code:
let binaryData: String = receivedMessage //receivedMessage has the
//binary data in string form
let image = UIImage(Data: receivedMessage) //error occurs here because
//receivedMessage is a
//String type argument
I know that in between those two lines, I need to convert the string to the Data type. How can I do that?
My data is NOT base-64 encoded, it is binary. It looks like (because it's not necessarily only ASCII values):
�|�zj\S^E#[�R��"D($�;jˊ^Tﰣu^F�q@��I$܂N�!AEI^V^Fޣ^X�Ѭ>�zBZ�!tiZ��^YqQ^R^AҔ�S�v^B3���1^Qzԥ4ْ���Ha��^@^E$�II^WI2d���j�^Cn,^HW�:��:$ @IB^ZJH^Q^Q�9E=:���-�V����J�B�^]q^M^W^\^@��1d��ƥ^RI&N<ǘ���~^B2b?x?��^@�"> ^@����������m�f��ր�^P��J�,��^E(X��$ ^@��y��}3�^@ԜG�^@}��^@YQ���^?�F^S�^@���nׄ]^Sя�t�?�=0���>k�^FT㓩Bu���b�8�Kî�蚿%5]^]ҵ)��5^]=�<�״9H�^V�ly�1�^N�� $ AJ�I) �y�1������^@?�<^/�Ծh�����Z������]eC�kU>RJ�^q��6�����,�1�^\yr}n�n*V�^S^[�B^BZ�$z��G����^?���<���s�#�B=��$ gT^TB�,�^D�XZ���^^b�7���^?턝��ֱ�,R��QR��^NhB�$������6^W�^X�xnO�F����dO���^@�y^@^K�^@�^^c�yojn��R�^@�̏W������^?�$ �mG�錩 Q�L�&H&I��7� ���0�__�^@-^]���1�=8������:=���^UVj^B|Ky ^A(��^Z@���^Y1�Z&�^[�^M^\��ƛK��Ŧ�����^^c���^@$ ��H^D�c�y�^V+��ng�r㷆�^@)��^@v~pm+�J�^@x��d��r^@ ��&~���}�h��U?���������y����g�^@��qN^G��^?�_^H²Kt�I��^W��n?N$ $�^H��c^P#�1�<�^\����^@����y�����+6^@xaN� �է���k�^W�✭Q�^L�Ћɟ���1�8�^S�g^S�^@^W?������C��^O�^Q�@ytf.�*B�+