Re: Shifting in Swift
Re: Shifting in Swift
- Subject: Re: Shifting in Swift
- From: Roland King <email@hidden>
- Date: Wed, 02 Jul 2014 21:28:54 +0800
let thirtyTwo : UInt32 = UInt32(CHUNK_SIZE_IN_BITS)
no automatic conversions in Swift (and the error message is another bug)
On 2 Jul, 2014, at 9:10 pm, Gerriet M. Denkmann <email@hidden> wrote:
> I am trying to convert an Objective-C class to Swift (just as a learning exercise):
>
> #define CHUNK_TYPE uint32_t // OSAtomicOr32 needs uint32_t
> #define CHUNK_SIZE_IN_BYTES ( sizeof(CHUNK_TYPE) )
> #define CHUNK_SIZE_IN_BITS ( CHUNK_SIZE_IN_BYTES * 8 )
>
> for( NSUInteger bix = 0; bix < CHUNK_SIZE_IN_BITS; bix++ )
> {
> CHUNK_TYPE a = (CHUNK_TYPE)0x1 << bix;
> }
>
>
> In Swift this becomes:
>
> typealias CHUNK_TYPE = UInt32
> let CHUNK_SIZE_IN_BYTES : Int = sizeof(CHUNK_TYPE)
> let CHUNK_SIZE_IN_BITS = CHUNK_SIZE_IN_BYTES * 8
>
> let one : CHUNK_TYPE = 0x1
> let thirtyTwo : UInt32 = CHUNK_SIZE_IN_BITS // Error: NSNumber is not a subtype of UInt32
>
> for var bix : UInt32 = 0; bix < thirtyTwo; bix++
> {
> let a = one << bix
> }
>
> But it does not work: I cannot convert an Int into UInt32.
>
> Should be possible, but I cannot find the (probably simple and obvious) solution.
>
> 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
_______________________________________________
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