Re: How to detect endian-ness in Swift?
Re: How to detect endian-ness in Swift?
- Subject: Re: How to detect endian-ness in Swift?
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Thu, 24 Jul 2014 09:03:59 +0700
On 24 Jul 2014, at 07:14, Chris Lattner <email@hidden> wrote:
>
> On Jul 23, 2014, at 2:59 AM, Gerriet M. Denkmann <email@hidden> wrote:
>
>> This compiles without warnings:
>>
>> #if __LITTLE_ENDIAN__
>> let encoding = NSUTF32LittleEndianStringEncoding;
>> println("LittleEndian")
>> #else
>> let encoding = NSUTF32BigEndianStringEncoding;
>> println("BigEndian")
>> #endif
>>
>> But it prints "BigEndian", which probably is NOT quite right.
>> How to correctly set my encoding?
>
> Swift doesn’t currently support any big endian targets, but you can test for it with something like:
>
> if Int(bigEndian: 42) == 42 {
> // is big endian
> }
>
> or:
>
> if Int(littleEndian: 42) == 42 {
> // is little endian
> }
This works fine:
var encoding : UInt
if Int(littleEndian: 42) == 42
{
// is little endian
encoding = NSUTF32LittleEndianStringEncoding;
}
else
{
encoding = NSUTF32BigEndianStringEncoding;
}
But it creates a warning: "Will never be executed" for the big-endian case.
I'm sure there will be a Swift endian build configuration switch "real soon now". So I will just live with this warning for now.
Thanks for this suggestion!
Kind regards,
Gerriet.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden