ios - How do I set integer endianness using htonl in Swift? -
ios - How do I set integer endianness using htonl in Swift? -
i'm trying set integer endianness using htonl() in swift compiler isn't finding htonl() method.
i've been using reference: append nsinteger nsmutabledata
here's code:
import foundation import cfnetwork import corefoundation var info = nsmutabledata() var number : uint32 = 12 var convertednumber : uint32 = htonl(number) data.appendbytes(&convertednumber, length: 4) i've been running in playground. error is:
use of unresolved identifier 'htonl'
update: martin r's reply right reply current versions of swift: http://stackoverflow.com/a/24653879/195691
--
you should utilize cfswapint32hosttobig() corefoundation method, htonl implemented c macro not work in swift.
however, looks doesn't work in swift playground. i'm getting error playground execution failed: error: error: couldn't lookup symbols: __osswapint32 despite fact corefoundation documentation includes method signatures in swift byte swapping methods.
interestingly, looks @ to the lowest degree part of <arpa/inet.h> has been ported swift, methods inet_ntoa() , inet_addr() available swift, htonl family not.
ios swift
Comments
Post a Comment