Shifting in Swift
Shifting in Swift
- Subject: Shifting in Swift
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Wed, 02 Jul 2014 20:10:07 +0700
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